Search code examples
google-chrome-extensionmanifest.json

Migrating Extension to Manifest v3


I want to Migrate My Chrome extension from manifest version 2 to version 3 because in near future Google will remove MV2 extension from their store. For now My extension Manifest code is like this.

{
    "browser_action": {
        "default_icon": "img/icon_active.png",
        "default_popup": "html/popup.html",
        "default_title": "Title here"
    },
    "description": "description here",
    "icons": {
        "128": "img/icon_128.png",
        "16": "img/icon_16.png"
    },
    "manifest_version": 2,
    "name": "Title here",
    "version": "1.0.1"
}

popup.js file look like this

$(document).on("click", ".copy-me", function(ev) {
    var $body = document.getElementsByTagName('body')[0];
    var rel = $(this).attr("rel");
    var text = $("#"+rel).text();
    var $tempInput = document.createElement("INPUT");
    $body.appendChild($tempInput);
    $tempInput.setAttribute("value",  text)
    $tempInput.select();
    document.execCommand("copy");
    $body.removeChild($tempInput);
});

Solution

  • Chrome Manifest v2 extensions deprecation timeline

    On January 17, 2022: Chrome Web Store no longer accepts new Manifest V2 extensions, however, developers will be allowed to push updates to them.

    In January 2023: Manifest V2 extensions will stop working and won’t run in Chrome, developers may not be able to push updates to them even with enterprise policy.

    Offical Resource


    I suggest you read the Google Chrome Offical Migration Article.

    If you don't want to spend your time on this, I suggest Extension Manifest Converter which is a tool that open-source and developed by Google.

    According to the README file, the tool has limitations:

    This tool aims to simplify the MV3 conversion; it does not fully automate the process. Only search and replace changes are applied to .js files.

    This tool does not:

    • update any service worker code that relies on a DOM

    I tried the tool and it gives me the below output:

    {
      "description": "description here",
      "icons": {
        "128": "img/icon_128.png",
        "16": "img/icon_16.png"
      },
      "manifest_version": 3,
      "name": "Title here",
      "version": "1.0.1",
      "action": {
        "default_icon": "img/icon_active.png",
        "default_popup": "html/popup.html",
        "default_title": "Title here"
      },
      "content_security_policy": {}
    }
    

    In your case manifest.json changed but nothing changed in popup.js.