-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test:playwright:open-browser script
Lets you open a headed browser which is configured to use the interception proxy. Useful for local debugging of browser tests.
- Loading branch information
1 parent
ff17a2c
commit 737f32d
Showing
5 changed files
with
40 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { openPlaywrightBrowser } = require('./playwrightHelpers'); | ||
|
||
(async function run() { | ||
await openPlaywrightBrowser(false /* headless */); | ||
})(); |
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,28 @@ | ||
const playwright = require('playwright'); | ||
const playwrightBrowsers = ['chromium', 'firefox', 'webkit']; | ||
|
||
async function openPlaywrightBrowser(headless) { | ||
const browserEnv = process.env.PLAYWRIGHT_BROWSER; | ||
|
||
if (!playwrightBrowsers.includes(browserEnv)) { | ||
throw new Error( | ||
`PLAYWRIGHT_BROWSER environment variable must be one of: ${playwrightBrowsers.join( | ||
', ', | ||
)}. Currently: ${browserEnv}`, | ||
); | ||
} | ||
|
||
const browserType = playwright[browserEnv]; | ||
|
||
// TODO undo this, trust the certs (it’s risky stuff though especially on e.g. a developer’s Mac where this potentially has global effect, although I guess it’s less risky given that we’re running as a different user) | ||
const browser = await browserType.launch({ headless }); | ||
// bypass localhost so that the proxy doesn’t need to be running in order for us to contact the control API to tell it to be started; TODO there is quite possibly a less convoluted way of starting the proxy in this case, also think in a more holistic manner about the various ways in which we make sure that only certain traffic is intercepted (there are notes dotted around about this) | ||
const page = await browser.newPage({ | ||
proxy: { server: 'localhost:8080', bypass: 'localhost' }, | ||
ignoreHTTPSErrors: true, | ||
}); | ||
|
||
return { browserType, browser, page }; | ||
} | ||
|
||
module.exports = { openPlaywrightBrowser }; |
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