Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Puppeteer configuration (#658)
* Centralises configuration for Puppeteer used in tests to make it easier to maintain. * Adds support for running tests on ARM, so we can use Raspberry Pi test runners off the cloud to get around block lists. * Includes improved stealth mode to avoid detection which breaks integration tests.
- Loading branch information
1 parent
2f0f738
commit 0adfba8
Showing
4 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const puppeteerExtra = require('puppeteer-extra') | ||
const StealthPlugin = require("puppeteer-extra-plugin-stealth") | ||
const stealthPlugin = StealthPlugin() | ||
|
||
// Override Puppeteer user agent to set 'navigator.platform' explicitly to | ||
// prevent detection on some providers (e.g. GitHub OAuth) as they force 2FA | ||
// on sign in if they detect sign in from a platform they haven't seen before. | ||
const puppeteerExtraPluginUserAgentOverride = require("puppeteer-extra-plugin-stealth/evasions/user-agent-override") | ||
stealthPlugin.enabledEvasions.delete("user-agent-override") | ||
puppeteerExtra.use(stealthPlugin) | ||
const pluginUserAgentOverride = puppeteerExtraPluginUserAgentOverride({ | ||
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36", | ||
platform: "MacIntel" | ||
}) | ||
puppeteerExtra.use(pluginUserAgentOverride) | ||
|
||
// CI is set to true by GitHub Actions to indicate is running in CD/CI | ||
const { CI } = process.env | ||
|
||
const puppeteerOptions = { | ||
headless: true // Set to 'false' to debug more easily | ||
} | ||
|
||
// When running on remote test runner (which is ARM) the executable path | ||
// needs to be set to 'chromium-browser' so it uses the ARM build of Chromium | ||
// not the x86 build that Puppeteer uses by default. Supporting this allows us | ||
// to test easily from remote locations that are outside cloud networks like | ||
// AWS, GPC, Azure, etc. and avoids tests being thwarted by IP blocklists. | ||
if (CI) | ||
puppeteerOptions.executablePath = 'chromium-browser' | ||
|
||
module.exports = { | ||
puppeteer: puppeteerExtra, | ||
puppeteerOptions | ||
} |
0adfba8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: