4

Here is a minimal extension for chrome in v3:

manifest.json

{
  "manifest_version": 3,
  "name": "Test",
  "version": "1.0",
  "description": "Test extension",
  "icons": {
    "48": "dark.png"
  },
  "background": {
    "service_worker": "button.js"
  },
  "permissions": [
    "activeTab"
  ],
  "action": {
    "default_icon": "dark.png",
    "default_title": "Test"
  }
}

button.js

chrome.action.onClicked.addListener(tab => {
  console.log('clicked')
  chrome.tabs.sendMessage(tab.id, { value: false })
});

The API seems quite clear in the doc. So I don't understand why, when I press the plugin button, I get weird errors:

extensions.js:4187 Uncaught TypeError: Failed to construct 'URL': Invalid URL
    at ExtensionsErrorPageElement.onSelectedErrorChanged_ (extensions.js:4187:2827)
    at Object.runObserverEffect [as fn] (polymer_bundled.min.js:1:37568)
    at runEffectsForProperty (polymer_bundled.min.js:1:37087)
    at runEffects (polymer_bundled.min.js:1:36604)
    at ExtensionsErrorPageElement._propertiesChanged (polymer_bundled.min.js:1:52973)
    at ExtensionsErrorPageElement._flushProperties (polymer_bundled.min.js:1:26564)
    at ExtensionsErrorPageElement._flushProperties (polymer_bundled.min.js:1:51737)
    at ExtensionsErrorPageElement._invalidateProperties (polymer_bundled.min.js:1:51534)
    at ExtensionsErrorPageElement._setProperty (polymer_bundled.min.js:1:51459)
    at ExtensionsErrorPageElement.Object.defineProperty.set (polymer_bundled.min.js:1:24863)
onSelectedErrorChanged_ @ extensions.js:4187
runObserverEffect @ polymer_bundled.min.js:1
runEffectsForProperty @ polymer_bundled.min.js:1
runEffects @ polymer_bundled.min.js:1
_propertiesChanged @ polymer_bundled.min.js:1
_flushProperties @ polymer_bundled.min.js:1
_flushProperties @ polymer_bundled.min.js:1
_invalidateProperties @ polymer_bundled.min.js:1
_setProperty @ polymer_bundled.min.js:1
Object.defineProperty.set @ polymer_bundled.min.js:1

What am I missing?

This is on Chromium Version 100.0.4896.75 (Build officiel) snap (64 bits)

Sharcoux
  • 5,546
  • 7
  • 45
  • 78
  • 1
    The code you've posted isn't related to the error. BTW you should use `chrome` instead of `browser`. – wOxxOm Apr 12 '22 at 20:20
  • Damn it, that was the issue... What a weird message to tell me that – Sharcoux Apr 12 '22 at 20:24
  • Now I get `Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.` – Sharcoux Apr 12 '22 at 20:25
  • I'll open another issue. This might help someone doing the same mistake – Sharcoux Apr 12 '22 at 20:27
  • That's because you need to have a content script running in the tab if you want to send a message there. See https://developer.chrome.com/extensions/messaging – wOxxOm Apr 12 '22 at 20:27
  • I have one. I just removed it because I had the other bug before. Check this https://stackoverflow.com/questions/71848934/uncaught-in-promise-error-could-not-establish-connection-receiving-end-does – Sharcoux Apr 12 '22 at 20:47
  • By the way, if you want to make a proper answer I'll accept it. – Sharcoux Apr 12 '22 at 20:48
  • IDK, almost a typo problem. – wOxxOm Apr 12 '22 at 20:55

2 Answers2

7

I had the same exception but with another reason.

So, i see the possible solution(how to get real error message).

I've set breakpoint on failed line and check the runtimeError message.

Can be usefull for somebody.

enter image description here enter image description here

Yahor Zhylinski
  • 503
  • 2
  • 10
-1
  1. Please remove node modules or take a clone of the repo in the new folder
  2. install node (npm install)
  3. npx cypress open

it works perfectly.