MV3 - Cannot get content script to run in Firefox! No errors and no loglines to be found!?

Hi!

As an early “proof-of-concept” (to sleep well at night), I tried to see how difficult it would be to migrate my Flickr Fixr webextension to MV3. Following the guide, I ended up only doing changes to the manifest.json file. So that was easy… Except the end-result didn’t work at all in Firefox, and I have no clue on why?!..

My non-persistent background-script (Event Page or what it is to be called now?) runs, and opens my “onboarding” page on install. And I can also open my extension’s Options page. But my content-script (Stigs_Flickr_Fixr.user.js) is totally ignored it seems. I have enabled a lot of log-statements in the content-script, but there are no log-lines to be found anywhere, nor any errors from the extension.

Completely lost on why it didn’t work, I tried replacing the non-persistent background script with a service-worker and installed the extension in Chrome. And voilà! Everything in the extension - including content-script - works fine (in Chrome)!

Does anybody have a clue on what could be going wrong in Firefox? I have tried both Nightly and Developer Edition, and I have changed the relevant flags in about:config.

Old MV2 manifest.json:

{
  "manifest_version": 2,
  "name": "Flickr Fixr",
  "short_name": "Flickr Fixr",
  "description": "Makes Flickr almost awesome - while waiting for SmugMug to fully fix it ;-)",
  "version": "1.12.0",
  "author": "Stig Nygaard",
  "homepage_url": "https://github.com/StigNygaard/Stigs_Flickr_Fixr",
  "permissions": [
    "https://*.flickr.com/*",
    "storage"
  ],
  "content_security_policy": "script-src 'self'; object-src 'none'",
  "icons": {
    "16": "icons/fr16.png",
    "32": "icons/fixr32.png",
    "48": "icons/fixr48.png",
    "64": "icons/fixr64.png",
    "96": "icons/fixr96.png",
    "128": "icons/fixr128.png",
    "256": "icons/fixr256.png"
  },
  "applications": {
    "gecko": {
      "strict_min_version": "52.0"
    }
  },
  "minimum_chrome_version": "67.0",
  "minimum_opera_version": "56.0",
  "minimum_edge_version": "79.0",
  "background": {
    "scripts": ["lib/mozilla/browser-polyfill.js", "background/flickr_fixr.js"],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": ["https://*.flickr.com/*", "*://*.flickr.net/*"],
      "exclude_matches": ["*://api.flickr.com/*", "*://identity.flickr.com/*", "*://*.flickr.com/signin/*", "*://*.flickr.com/signup/*", "*://*.flickr.com/account/*"],
      "js": ["lib/mozilla/browser-polyfill.js", "options/options.js", "Stigs_Flickr_Fixr.user.js"],
      "run_at": "document_start"
    }
  ],
  "web_accessible_resources": ["inject/timeout.js"],
  "options_ui": {
    "page": "options/options.html",
    "browser_style": true,
    "chrome_style": true,
    "open_in_tab": true
  }
}

New MV3 manifest.json:

{
  "manifest_version": 3,
  "name": "Flickr Fixr",
  "short_name": "Flickr Fixr",
  "description": "Makes Flickr almost awesome - while waiting for SmugMug to fully fix it ;-)",
  "version": "1.12.0",
  "author": "Stig Nygaard",
  "homepage_url": "https://github.com/StigNygaard/Stigs_Flickr_Fixr",
  "permissions": [
    "storage"
  ],
  "host_permissions": [
    "https://*.flickr.com/*"
  ],
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'none'"
  },
  "icons": {
    "16": "icons/fr16.png",
    "32": "icons/fixr32.png",
    "48": "icons/fixr48.png",
    "64": "icons/fixr64.png",
    "96": "icons/fixr96.png",
    "128": "icons/fixr128.png",
    "256": "icons/fixr256.png"
  },
  "applications": {
    "gecko": {
      "strict_min_version": "103.0"
    }
  },
  "minimum_chrome_version": "103.0",
  "minimum_opera_version": "89.0",
  "background": {
    "scripts": ["lib/mozilla/browser-polyfill.js", "background/flickr_fixr.js"],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": ["https://*.flickr.com/*", "*://*.flickr.net/*"],
      "exclude_matches": ["*://api.flickr.com/*", "*://identity.flickr.com/*", "*://*.flickr.com/signin/*", "*://*.flickr.com/signup/*", "*://*.flickr.com/account/*"],
      "js": ["lib/mozilla/browser-polyfill.js", "options/options.js", "Stigs_Flickr_Fixr.user.js"],
      "run_at": "document_start"
    }
  ],
  "web_accessible_resources": [
    {
      "resources": [ "inject/timeout.js" ],
      "matches": [ "https://*.flickr.com/*" ]
    }
  ],
  "options_ui": {
    "page": "options/options.html",
    "browser_style": true,
    "open_in_tab": true
  }
}

Modifications to run in Chrome:

To make it run in Chrome, I removed the “options_ui”.“chrome_style” property (apparently doesn’t like that with MV3) and replaced the “background” property in above with

"background": {
  "service_worker": "background/flickr_fixr.js",
  "type": "module"
},

and included the browser-polyfill.js script in flickr_fixr.js with:

import * as Module from '/lib/mozilla/browser-polyfill.js';

(I don’t think polyfill adds anything to Module, but browser namespace API works in Chrome after this)

Yeah, we all have this problem and it’s a known thing:

It’s good that you are testing testing MV3, but it’s still way too soon :slight_smile:. Many API is still missing and I don’t think you will be able to release MV3 addon this year.

And seeing how fast the development goes, I would say we will be lucky if ESR 114 in September 2023 has a full MV3 support :frowning:. Not to mention features that Chrome is still working on, like the Offscreen Document.

2 Likes

Ah… Going to the “permissions tab” was really a simple quick fix :slight_smile: :heavy_check_mark:

I had no plan to release an MV3-update “soonish”. Just wanted to find out how big a task it would be to migrate when time comes. However that being said, I sure do hope Firefox would have official MV3-support by end of year when Google stops accepting MV2 updates to their extensions.

I don’t use build-scripts to create my extensions. I like the beautiful concept of being able to create one extension-file for use with all browsers simply by zipping content of a folder from my repository. I was worried background-scripts vs background-workers would be an issue here, but if MV3 for Firefox wont even be ready when Google stops supporting MV2, that’s much bigger of an issue :frowning:

But thanks a lot for your fix (that worked) and the (slightly depressing) update on development-status.

1 Like

The blog post by mozilla from May 18 said:

we expect to launch MV3 support for all users by the end of 2022

Also MV2 will stop working in chrome from 2023, so I expect mozilla will keep their promise, otherwise extension developers will be forced to maintain two versions at once.

The problem is the ESR version - it’s released only once a year (around September). And it’s been said that this year ESR 102 won’t support MV3.

So either you drop support for ESR 102 by the end of this year or you will have to maintain MV2 and MV3 versions of your addon till the September 2023.