Hello! I had a MV2 script that was persistent, and it worked like a charm. After migrating to MV3, I noticed the script runs for about 30 seconds, and then it says Stopped. I know this is intended behavior, as it helps reduce load on the browser, etc. My issue is that when the script is activated after being stopped (I can see it go from Stopped to Running in about:debugging), it doesn’t appear to work.
What I’m trying to do is pretty simple… add a context menu, and when that context menu is clicked, it executes a JS file. When I initially load (or manually reload) the script and click the context menu before it stops, it works flawlessly, but like I said, when it stops and gets awakened from the context menu click, it doesn’t work.
Here’s what I’ve got:
// details.copy.background.js
browser.contextMenus.create({
id: "details-copy",
title: "Copy Details",
});
browser.contextMenus.onClicked.addListener((data, tab) => {
browser.scripting.executeScript({
target: { tabId: tab.id, allFrames: true },
files: ['details.copy.context.js']
});
});
My manifest file looks like this:
"manifest_version": 3,
"name": "Testing Context Menu",
"version": "1.0",
"description": "Test",
"permissions": [
"clipboardWrite",
"contextMenus",
"tabs",
"activeTab",
"scripting"
],
"icons": {
"48": "icon.png"
},
"background": {
"scripts": [
"details.copy.background.js"
]
},
...omitted content_scripts
"web_accessible_resources": [
{
"matches": [
"<all_urls>"
],
"resources": [
"my_resource.js"
]
}
]
I have read a whole bunch of other threads on this, but I didn’t see a clear solution, so I apologize that I’m asking for the umpteenth time, but I’m obviously doing something wrong. Any help would be appreciated!