-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for using existing cdp websocket in launchServer #4344
Closed
+141
−14
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0122986
feat: add support for using existing cdp websocket in launchServer
berstend 1b67b5c
Merge branch 'master' into add-cdp-endpoint-support
berstend 2e8f650
fix: remove optional chaining
berstend fe4c9d3
fix: switch to dedicated onUpgrade handler
berstend e4f57a3
test: add smoke test for cdp websocket connection
berstend 1f2e6cc
feat: add dedicated browserType.connectServer api
berstend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -16,8 +16,9 @@ | |
*/ | ||
|
||
import { it, expect, describe } from './fixtures'; | ||
import http from 'http'; | ||
|
||
describe('lauch server', (suite, { wire }) => { | ||
describe('launch server', (suite, { wire }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought I fix that while I'm there 😄 |
||
suite.skip(wire); | ||
}, () => { | ||
it('should work', async ({browserType, browserOptions}) => { | ||
|
@@ -62,4 +63,42 @@ describe('lauch server', (suite, { wire }) => { | |
expect(result['exitCode']).toBe(0); | ||
expect(result['signal']).toBe(null); | ||
}); | ||
|
||
it('should add user-agent to websocket request', async ({ browserType, server}) => { | ||
const getUserAgent = () => new Promise(async resolve => { | ||
server.setRoute('/websocket', async (req, res) => { | ||
resolve(req.headers['user-agent']); | ||
}); | ||
browserType.launchServer({ | ||
cdpWebsocketEndpoint: server.PREFIX + '/websocket' | ||
}); | ||
}); | ||
const ua = await getUserAgent(); | ||
expect(ua).toContain('playwright/'); | ||
}); | ||
|
||
it('should allow using an existing cdp endpoint', async ({ testWorkerIndex, browserType, server}) => { | ||
const fetchUrl = (url: string): Promise<string> => new Promise((resolve, reject) => { | ||
http.get(url, resp => { | ||
let data = ''; | ||
resp.on('data', chunk => { data += chunk; }); | ||
resp.on('end', () => { resolve(data); }); | ||
}).on('error', (err: Error) => { reject(err); }); | ||
}); | ||
const debuggingPort = 8100 + testWorkerIndex; | ||
await browserType.launchServer({ | ||
args: [`--remote-debugging-port=${debuggingPort}`] | ||
}); | ||
const version = await fetchUrl(`http://localhost:${debuggingPort}/json/version`); | ||
const cdpWebsocketEndpoint = JSON.parse(version).webSocketDebuggerUrl; | ||
const browserServer = await browserType.launchServer({ cdpWebsocketEndpoint }); | ||
const wsEndpoint = browserServer.wsEndpoint(); | ||
const browser = await browserType.connect({ wsEndpoint }); | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
await page.goto(server.EMPTY_PAGE); | ||
expect(page.url()).toContain('empty.html'); | ||
const answer = await page.evaluate(() => 6 * 7); | ||
expect(answer).toBe(42); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the right way is to connect right here, in the BrowserServerImpl, instead of going all the way to _innerLaunch and back.
Now that I think about this more: when connecting over existing cdp, all other launch parameters are actually ignored. This hints at using a different method, something like
chromium.connectServer
that only takes the websocket url. WDYT?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.
I agree, when connecting to an existing cdp websocket virtually all of the launch code isn't needed. Also the flag feels a bit shoehorned into there, so it might be cleaner to keep it separate. If promoting this feature to it's own top-level API is fine then I'm happy to work on the changes 😄
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.
Added a dedicated API implementation for comparison