Closed bershanskiy closed 2 years ago
I spent some time attempting to move to a non-persistent background script today but was unable to get it working.
If I'm understanding correctly in order to use a non-persistent background script correctly I would need to move the toolsPorts
and pagePorts
maps into chrome.storage.local
but, unfortunately, these maps store message passing ports which are not serializable.
You are welcome to take a crack at it if you wish but I do not believe it will work with the current architecture.
If I'm understanding correctly in order to use a non-persistent background script correctly I would need to move the
toolsPorts
andpagePorts
maps intochrome.storage.local
but, unfortunately, these maps store message passing ports which are not serializable.
Not exactly. Chrome persists the background context for as long as it has at least one open port, so you don't need to serialize ports. This persistence is both a blessing (ease of development) and a curse (efficiency loss), so I personally prefer avoiding ports and using messages.
I spent some time attempting to move to a non-persistent background script today but was unable to get it working.
What problem are you facing?
You are welcome to take a crack at it if you wish but I do not believe it will work with the current architecture.
I'd actually prefer just using regular message passing, if that's OK with you. I have a working local repo which works for me, can file a PR if you are interested.
If you have something working by all means create a pull request and I'll look at it.
I didn't document my changes very well by making small commits, so the diffs are rateher long and not all changes are relevant. I'll split changes out in logical chuncks for simpler review and file incremental PRs. I'll make sure to reference this bug to help keep track.
Take your time. I appreciate the help.
@RedHatter I have updated the top comment with a tentative plan. Feedback is welcome.
Edit: typo
Technically, it would be fine to declare background non-persistent already (because background would be kept alive all the time when at least one Svelte DevTool tab is open), but I'd like to get #53 merged and do task 5 before that.
@RedHatter I filed all the PRs which I could without depending on already existing PR. I still expect some PRs to have merge conflict which I can resolve after the first PR is merged. What do you think of what is already there?
Closing as obsolete.
Describe the bug Background page should not be persistent.
To Reproduce Steps to reproduce the behavior:
Expected behavior When extension is not in use, it should not consume computer resources (RAM).
Environment
Additional context If you are interested, I can file a PR to fix this. Right now, only Chrome supports non-persistent pages, but Firefox plans to add support soonTM.
Plan I will break up this into a few PRs. Here is a tentative plan (no particular order):
WIP (all these are blocked on already opened PRs):
chrome.storage.local
when neededmanifest.json
and test it!Review:
62
Optimization: avoid
chrome.tabs.onUpdated
because it is triggered for every single other tab. Frequent callback runs restore background into active state unnecessarily.60
Done:
54 Removes
pagePorts
insrc/background.js
53 Fix: background has two handlers for
'startProfiler'
(one is dead) and no handler for'stopProfiler'
53 Get rid of gloal
profilerEnabledList
insrc/background.js
Value of this variable is set in DevTools tab and is used in content script. It makes sense to store it in either one, but not in background.
Edit: add plan!