How to pass the userAgent value in the backstop.json file
- Dominant language
- JavaScript
- Stars
- 7.2k
- Forks
- 621
- PR merge metrics
- No merged PRs in 30d
Description
Our company has recently installed CloudFlare on our platform to set rate limiting. I need to be able to set a custom userAgent value so we can identify the backstop tests as good traffic vs. a bad actor trying to do something malicious.
We currently do not commit (via .gitignore) the backstop.json file and /backstop_data/ folder; we do commit a default.backstop.json file to be saved with our various github repositories that has the various scenarios for each site.
Our default.backup.json files already has a "onReadyScript": "puppet/onReady.js". I tried adding it with "onReadyScript": "async (chromy, scenario) => { await chromy.userAgent('Your User-Agent String'); }" in the main body of the script - it did not recognize or find chromy.on.
I did try to include both the puppet/onReady.js and the await chromy.userAgent arguments in a single onReadyScript using "onReadyScript": "chromy.on('ready', function() { action1(); action2(); });" format: My attempts were:
- "onReadyScript": "chromy.on('ready', function() { var fileContent = require('fs').readFileSync('path/to/file.txt', 'utf-8'); await page.setUserAgent(''Your User-Agent String'); });"
- "onReadyScript": "chromy.on('ready', function() { var fileContent = require('fs').readFileSync('path/to/file.txt', 'utf-8'); /* Rest of your script */ });"
- "onReadyScript": "puppet/onReady.js('ready', function() { await page.setUserAgent('Your User-Agent String'); });"
Some of these may not be the exact values in my tests - so please feel free to correct my syntax.
I have also tried setting "userAgent": "Your User-Agent String" in several places: in the viewports section, scenarios, and in the engineOptions.
None of these have worked for me.The only way I have successfully set userAgent is via onReady.js changes (but we do not commit that file to our repositories). I need help to find a way to pass a userAgent value in the backstop.json file. Thank you in advance.
Contributor guide
Assessment
This issue has not been assessed yet.