问题
I'm trying to make my chrome extension visit an URL when it is uninstalled. Apparently chrome.runtime.setUninstallUrl is the best (and only?) option, but it doesn't seem to work for me. It's not firing at all.
This is the code I use:
chrome.runtime.setUninstallURL('www.google.com');
It's located in the extension's background JavaScript file together with a couple of other event listeners. I tried loading my unpacked extension into Chrome and then removing it, but the uninstall URL does not budge.
Any help would be appreciated.
回答1:
Update
The feature landed in Chrome 41, so the answer is mostly obsolete - it should work now.
The documentation displays a warning:
Dev channel only.
This means that this API function is still considered experimental and not enabled in Stable/Beta builds of Chrome.
Here's the corresponding issue in the Chrome bug tracker. Seems like this feature should hit stable soon (ready since July) but got a bit lost on its way. Consider starring the issue to raise its priority.
Until it is fixed, it won't work in normal Chrome versions. You should have seen an error that the function is undefined if you looked in the background console, by the way.
You can already safely include it in your code conditionally, so it will work on builds where it's enabled:
if(chrome.runtime.setUninstallURL) {
chrome.runtime.setUninstallURL('http://example.com/');
} else {
// Not yet enabled
}
回答2:
The URL must have an http: or https: scheme.
来源:https://stackoverflow.com/questions/26752114/chrome-runtime-setuninstallurl-doesnt-seem-to-be-working