'Uncaught TypeError: Failed to construct 'URL': Invalid URL in chrome extension v3 when using messages

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)



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1