Context:
--remote-debugging-port=12345 to enable websocket server.Code Snippet
const {chromium} = require('playwright');
(async () => {
const browser = await chromium.connect({wsEndpoint: `ws://127.0.0.1:12345/devtools/browser/451b2fcb-131f-4baa-9315-3a45ff927361`});
const contexts = await browser.contexts()
})();
Describe the bug
I have launched browser from CLI and pass the wsEndpoint manually to the scripe. By doing so I am expecting browser.contexts() to return at-least one browser context (of the browser page that's already open). It seems that browser.contexts() returns contexts opened by playwright only and not the ones that might already be there.
This might be just a documentation bug, but I was expecting it to work with all the contexts.
Hi,
unfortunately it's not supported to use the normal websocket connection by Chrome and use it in combination with Playwright. As a websocket URL, you need to use the URL which you can get by using the launchServer() function.
const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.
(async () => {
const browserServer = await chromium.launchServer();
const wsEndpoint = browserServer.wsEndpoint();
// Use web socket endpoint later to establish a connection.
const browser = await chromium.connect({ wsEndpoint });
// Close browser instance.
await browserServer.close();
})();
This issue seems related: #1985
Hey @mxschmitt Thanks for the explanation. I see the difference in the URLs.
Normal WS URL: ws://127.0.0.1:12345/devtools/browser/451b2fcb-131f-4baa-9315-3a45ff927361
Playwright's WS endpoint: ws://127.0.0.1:54301/13e2362cf8a76db22eb1d06ff4032ff6
After reading more on #1985 I also understand the underlying reasoning. Maybe you can suggest a solution for what I am trying to achieve.
The goal is to launch a browser on server that's always up. I want to ensure that I can sign in to that browser and it will retain my credentials. Even after I restart my VM, the browser will retain all the user preferences, cookies etc. The way to achieve this would be to use both wsEndpoint and userDataDir.
Currently with playwright I can either use
launchPersistentContext with userDataDir but no wsEndpoint, orlaunchServer with wsEndpoint but no userDataDirI asked it as a question here as well: #2995
Any suggestion would be helpful. Thanks!
@VikramTiwari Closing this in favor of #2995 then to continue discussion over there.
Thanks @aslushnikov Sounds good!
Most helpful comment
Hey @mxschmitt Thanks for the explanation. I see the difference in the URLs.
Normal WS URL:
ws://127.0.0.1:12345/devtools/browser/451b2fcb-131f-4baa-9315-3a45ff927361Playwright's WS endpoint:
ws://127.0.0.1:54301/13e2362cf8a76db22eb1d06ff4032ff6After reading more on #1985 I also understand the underlying reasoning. Maybe you can suggest a solution for what I am trying to achieve.
The goal is to launch a browser on server that's always up. I want to ensure that I can sign in to that browser and it will retain my credentials. Even after I restart my VM, the browser will retain all the user preferences, cookies etc. The way to achieve this would be to use both
wsEndpointanduserDataDir.Currently with playwright I can either use
launchPersistentContextwithuserDataDirbut nowsEndpoint, orlaunchServerwithwsEndpointbut nouserDataDirI asked it as a question here as well: #2995
Any suggestion would be helpful. Thanks!