chrismbryant / amazon-confidence-interval

A browser extension which adds Bayesian visualizations to Amazon ratings.
MIT License
31 stars 4 forks source link

Declarative injection? #11

Closed musicin3d closed 4 years ago

musicin3d commented 4 years ago

I'm curious why we're using programmatic injection. I noticed that we are manually re-injecting after navigation events, and we've made it handle being rerun. As I understand it, declarative injection automatically injects the content script into each page that matches the pattern. It seems to me that would remove some boilerplate. [How] does this project benefit from doing it programmatically?

aeciorc commented 4 years ago

Hey @musicin3d, earlier I tried injecting via content_scripts, but that wouldn't trigger the script when the user navigates between different pages of search results or performs another search. So I did it programatically because the {status: 'complete'} event covers all those cases. I guess I could inject declaratively and listen to location changes in the script itself, although that would come with its own boilerplate. My experience with developing extensions is somewhaat limited, so let me know if you can think of a better way

musicin3d commented 4 years ago

Mine is as well. It was a curious question. If that's what it takes then that's what it takes. I'll leave this ticket open for a few days to see if anyone else chimes in.

musicin3d commented 4 years ago

https://developer.chrome.com/extensions/content_scripts

Content scripts run in an "isolated world," so we don't need to control scope or try to avoid collisions as long as we don't put things into window

aeciorc commented 4 years ago

I saw that, but the isolated environment is the same for all injected scripts. So if my script isconst a =1 and I run it twice, it will cause Uncaught SyntaxError: Identifier 'a' has already been declared