Chromium extension can't establish connection with receiver with Playwright-Java
See original GitHub issueWe have an extension that adds a listener to establish a channel with a cloud service, which works fine when side-loading the extension, or using Playwright-Javascript. With the Java implementation, the extension logs the following to the console:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
I believe it’s occurring when the extension make this call (or something similar):
.extension.onRequest.addListener((e, t, n) => { t.id === chrome.runtime.id && "?" === e.locked && n({state: this.locked, message: this.lastMessage}) })
The call to .launchPersistentContext is nearly identical to the one that works in Playwright-Javascript:
Path userDataDir = Paths.get("/tmp/chrome-user" + Integer.toString(instanceCount));
String extensionPath =
"./src/test/java/classroom/resources/extensions/crx-" + ClassroomPlaywright.env.getString("customerID");
List<String> chromeArgs = new ArrayList<>();
chromeArgs.add("--disable-background-timer-throttling");
chromeArgs.add("--disable-backgrounding-occluded-windows");
chromeArgs.add("--disable-renderer-backgrounding");
chromeArgs.add("--no-sandbox");
chromeArgs.add("--disable-setuid-sandbox");
chromeArgs.add("--disable-dev-shm-usage");
chromeArgs.add("--disable-extensions-except=" + extensionPath);
chromeArgs.add("--load-extension=" + extensionPath);
BrowserType.LaunchPersistentContextOptions options = new BrowserType.LaunchPersistentContextOptions();
options.channel = BrowserChannel.CHROME;
options.setHeadless(false);
options.setDevtools(false);
options.args = chromeArgs;
studentContext = student.chromium().launchPersistentContext(userDataDir, options);
studentPage = studentContext.pages().get(0);
I also tried options.setIgnoreAllDefaultArgs
and switched off all but the 2 needed for loading the extension, but the error still occurred.
I may be able to provide the extension source, if it will help to debug
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Yes!!! That was a very good observation, indeed! I can’t believe I did that. The bug was all mine. The /dest directory has the extension with the user email poked into the index.js for the extension.
Thank you Yury!!! You may happily close this one out
Try running both java and nodejs versions with
DEBUG=pw:browser
environment variable and see what are the actual command line options passed to chrome in each case. If it’s the same binary, launched with the same arguments the behavior should not differ.