You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background: Under MV3, the extension background page is no longer persistent; it terminates after a period of inactivity and restarts for the next event.
Problem 1: webext-redux doesn't support mv3
Fixed:tshaddix/webext-redux#297 (published this PR as webext-redux@3.0.0-mv3.0, will publish as latest soon)
The port object used by the store will become disconnected if the service worker sleeps, preventing the store from receiving updates.
Solution 1.1: use chrome.runtime.sendMessage instead of ports
Solution 1.2: pass custom port object that handles disconnects
webext-redux takes a port name string, not a port object, so this requires changes to webext-redux. Long-term maybe not a good idea since using native ports would be a common footgun for webext-redux users.
Problem 2: state is lost when service worker restarts
Fixed: Solution 2.1 is working well (chrome.storage.session).
Solution 2.1: persist state
chrome.storage.session and chrome.storage.local
10 MB limit (each)
Maybe only persist files until they're saved?
Might require truncation logic to drop files to make state fit?
Solution 2.2: keep-alive
While a panel is open, ping the service worker using chrome.runtime.sendMessage() to keep it alive. It would be nice to allow the service worker to sleep but this is a quick fix, especially considering webext-redux will need changes to support the service worker sleeping.
After testing, this may not work. if panel pings service worker, the interval can be throttled by Chrome when it's in the background. the worker will miss pings and go to sleep. an interval in the service worker is more reliable, but it won't fire while the computer is asleep, still causing dropped pings and the service worker to sleep. tested with 25s and 5s interval
Solution 2.3: don't sync panels anymore
they can all have their own state, fetching, saving (continue using chrome sync storage for settings)
Solution 2.4: sync panels using chrome.storage.session
Replaces webext-redux
10 MB limit
Use service worker to save data
Problem 3: Content Security Policy blocks linter worker
Fixed: disabled ace option loadWorkerFromBlob
Refused to load the script 'chrome-extension://afioclbfmnhmggdeelmdhdhcfchbjhbf/worker-javascript-eslint.js' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:*". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'chrome-extension://afioclbfmnhmggdeelmdhdhcfchbjhbf/worker-javascript-eslint.js' failed to load.
at blob:chrome-extension://afioclbfmnhmggdeelmdhdhcfchbjhbf/00335355-995f-4e8a-8bb7-2f0cf4c3790a:1:1
Other notes
Tried testing MV2 event page behavior but it's not sleeping for some reason. Could investigate this more but not sure it really matters.
Idea: Create a port wrapper that reconnects when the background wakes or the service worker restarts
Idea: Create a timer lib that setups up chrome alarms for timers beyond 30s
When device sleeps, related events (disconnect ports, offline event) fires when the computer wakes, right before the online event.
Events
Time
Offset
Duration
Event
9:20:48 AM
0 s
17 s
Port connected
9:21:06 AM
18 s
10502 s
Set pinging to true
12:16:08 PM
10502 s
0 s
Connection changed to offline
12:16:08 PM
0 s
0 s
Port disconnected
12:16:08 PM
0 s
0 s
Port connected
12:16:11 PM
3 s
41 s
Connection changed to online
The text was updated successfully, but these errors were encountered:
Background: Under MV3, the extension background page is no longer persistent; it terminates after a period of inactivity and restarts for the next event.
Problem 1: webext-redux doesn't support mv3Fixed: tshaddix/webext-redux#297 (published this PR as
webext-redux@3.0.0-mv3.0
, will publish aslatest
soon)The port object used by the store will become disconnected if the service worker sleeps, preventing the store from receiving updates.
chrome.runtime.sendMessage
instead of portsSolution 1.2: pass custom port object that handles disconnectsProblem 2: state is lost when service worker restartsFixed: Solution 2.1 is working well (chrome.storage.session).
chrome.runtime.sendMessage()
to keep it alive. It would be nice to allow the service worker to sleep but this is a quick fix, especially considering webext-redux will need changes to support the service worker sleeping.Problem 3: Content Security Policy blocks linter workerFixed: disabled ace option
loadWorkerFromBlob
Other notes
Tried testing MV2 event page behavior but it's not sleeping for some reason. Could investigate this more but not sure it really matters.
Idea: Create a port wrapper that reconnects when the background wakes or the service worker restarts
Idea: Create a timer lib that setups up chrome alarms for timers beyond 30s
When device sleeps, related events (disconnect ports, offline event) fires when the computer wakes, right before the online event.
Events
The text was updated successfully, but these errors were encountered: