question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] extension message passing in non-persistent context

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pavelfeldmancommented, Nov 19, 2020

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.

1reaction
aslushnikovcommented, Nov 17, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found