Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

chrome.runtime missing properties in manifest v3

I am trying to migrate my browser extension to manifest version 3 but I am not able to access some properties from chrome.runtime in my service_worker. Code explains more than words I guess.

My background.js file:

function call() {
    console.log({ runtime: chrome.runtime })
    chrome.runtime.getPackageDirectoryEntry(() => null)
}

// putting it to timeout otherwise I couldn't access the logs page
setTimeout(() => {
    call()
}, 0)

My manifest:

{
    "manifest_version": 3,
    "name": "Test",
    "version": "0.0.0",
    "background": {
        "service_worker": "background.js"
    }
}

When I open service worker page I can see

Uncaught TypeError: chrome.runtime.getPackageDirectoryEntry is not a function

The same code works with v2:

{
    "manifest_version": 2,
    "name": "Test",
    "version": "0.0.0",
    "background": {
        "scripts": ["backgroud.js"]
    }
}

The method I am trying to use is documented here but it is clearly missing in the runtime object (with plenty of others...)

question from:https://stackoverflow.com/questions/66066405/chrome-runtime-missing-properties-in-manifest-v3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...