[Feature] extension message passing in non-persistent context
See original GitHub issueContext:
- Playwright Version: 1.5.1, 1.6.1
- Operating System: Mac (local) Linux (via CI)
- Node.js version: 14.x
- Browser: Chromium
- Extra: non-headless
Code Snippet
chrome.tabs.sendMessage
fails on fails on chromium.launch
, but not on chromium.launchPersistentContext
// @filename content.js
chrome.runtime.sendMessage(undefined, message)
// @filename background.js
chrome.runtime.onMessage.addListener((message, sender) => {
if (typeof sender?.tab?.id !== 'number') return
chrome.tabs.sendMessage(sender.tab.id, message, { frameId: 0 }) // 💥
})
💥
"Could not establish connection. Receiving end does not exist."
Describe the bug
I’ve created a repo to further describe and isolate this bug.
the only dependencies are node
and playwright
itself.
the log on GitHub Actions help with visualising the mismatch between the persistent context and the default ones.
I wasn’t able to reproduce it on a Chromium Incognito window locally. 🤔
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Chrome Extensions Message passing
Communication between extensions and their content scripts works by using message passing. Either side can listen for messages sent from the ...
Read more >Basic google chrome extension message passing not working
I've been trying to get message passing for a chrome extension to work but console.log(response) gives me undefined. I've looked at the docs...
Read more >Begin your MV3 migration by implementing new features today
MV3 changes you can make to your extension right now. Event Pages. In Firefox MV3, we're providing Event Pages as the background script....
Read more >Service Worker in Browser Extensions | by Madhura Mehendale
With the introduction of the new version, the background page of the extension is ... with the webpage through asynchronous message passing.
Read more >Chrome Extension Tutorial: How to Pass Messages from a ...
Message Passing : Interaction Between Scripts · Popup Script - Local JavaScript file for the extension DOM · Background Script - Provides ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is by design. At this point, support for extensions in Playwright is in the best effort mode. We focus on the cross-browser web testing instead. In order to test extensions, you should run Playwright in a mode that is as close to the regular execution as possible, in this case it means running it as
chromium.launchPersistentContext
and specifying the user data dir.@leonardodino by default, extensions don’t run in incognito windows in Chromium (so they don’t run for you in the Playwright default context). I tried with your extension, and it doesn’t run in incognito as well. Could it be that you explicitly enable it in extension settings?