Skip to content
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

[Feature] extension message passing in non-persistent context #4441

Closed
leonardodino opened this issue Nov 15, 2020 · 5 comments
Closed

[Feature] extension message passing in non-persistent context #4441

leonardodino opened this issue Nov 15, 2020 · 5 comments

Comments

@leonardodino
Copy link

Context:

  • 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. 🤔

@aslushnikov
Copy link
Contributor

I wasn't able to reproduce it on a Chromium Incognito window locally. 🤔

@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?

image

@leonardodino
Copy link
Author

leonardodino commented Nov 17, 2020

Hey there @aslushnikov thanks for the quick turn around!

sorry! I indeed wrote it a bit weird 😅
I was able to get it working on chrome+chromium install, after enabling this flag.

The extension fails when running on playwright (and puppeteer) in a way that I'm not able to reproduce on regular browsers:

browser persistent incognito
chrome Screen Shot 2020-11-17 at 12 39 38 Screen Shot 2020-11-17 at 12 39 33
chromium Screen Shot 2020-11-17 at 12 47 35 Screen Shot 2020-11-17 at 12 47 39
playwright Screen Shot 2020-11-17 at 12 41 33 Screen Shot 2020-11-17 at 12 41 40

I'm also enabling the "run in incognito" on the plawright run. 😄

(the first console.log checks that the extension's content.js successfully ran and has injected a div)

$ node .
==== persistent ====
DOM insertion: true
clock updated: true
==== inconigto ====
DOM insertion: true
clock updated: false 

@pavelfeldman
Copy link
Member

chrome.tabs.sendMessage fails on fails on chromium.launch, but not on chromium.launchPersistentContext

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
Copy link
Author

Hey, thanks again for the support (:

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.

Fully understand and support this decision! 🙌 extensions are indeed an edge-case.
and I'm happy they are supported, even if by chance! 😄

running it as chromium.launchPersistentContext and specifying the user data dir.

yep, using it currently, together with jest-playwright and everything works. 💯

just wanted to report because it took me a good while to understand why it was failing 😅
hopefully can save some minutes/hours for the next one.

@dgozman dgozman changed the title [BUG] extension message passing in non-persistent context [Feature] extension message passing in non-persistent context Nov 23, 2020
@pavelfeldman
Copy link
Member

Thank you for reporting this issue and providing comments to those that might be facing a similar problem. I am now closing this as a part of the triage, please feel free to file a new issue with additional details. Given the limited resource and a lot of requests, we need to fulfill most popular requests and at the same time keep our issue database manageable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants