-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient way to add more content scripts #37
Comments
You can inject scripts via manifest (which I'd recommend) or by using an inject script as we do in development. For both cases you have to generate every bundle. Probably a better a way in your case would be to delegate a part of the functionality to the background script. So you can have a small universal injected script, which will just investigate the page and will communicate with the background (sending specific commands and receiving the response from the background script). |
thanks for the quick & thorough answer, @zalmoxisus if i can ask a followon: one of my scripts that might be too big to load everywhere is a scraper that fetches a few dozen DOM nodes with numerous I ended up putting it in the injection function because I didn't think I could access raw DOM nodes thru React components. Most of my scripts either scrape, or populate existing DOM nodes, in fact. Are those types of functions possible within React components in this setup? Or are those best left to regular injection functions? I thought of sending the entire DOM to the background to parse there, but I imagine that would be even more of a burden on the UX than the slight lag in loading the current technique experiences. |
thanks @zalmoxisus . so far injecting through the script body is working great with minimal hits to load times. One more question: if I inject a content script that dispatches an action creator (e.g., I ask b/c I have an action creator that does some async stuff, and i'd like to keep it contained in the background. I tried figuring it out from the src code, but having trouble connecting the dots |
Hey @brandonmp, Sure, everything you import in that injected script will be part of it. Unlike windows, the injected scripts are independent from the background script. You can have a different store and different action creators there. So you can have in the injected script an action which requests an async request and on background another action that executes the async stuff. |
Okay, I took a much closer look at the counter example and I think I was just missing some key points in how the extension/background communicate. Can you tell me if this understanding is correct?
So, if all that is correct, it seems like the best way to keep logic in the background is to have two separate action creators for a process
Appreciate your help with this. This project has been a tremendous help in learning more about extensions (and redux too) eta: if i'm correct about the process and it'd be helpful, i'm happy to extend the repo's readme |
Yes, you got the point, and having several action types dispatched for an async task is a good practice. For example: In some projects I don't have action creators at all, and just do About extending the repo's readme, it would be really welcome to have a |
I'm new to Chrome extensions, so forgive me if this question isn't unique to this project.
I'm trying to add multiple content scripts, each of which injects into a different url.
Is there a straightforward way to do this? So far the best i can figure out is:
However, that a) seems way too complicated and b) isn't working for me.
has anyone done this? My content scripts are too big to inject in every page.
The text was updated successfully, but these errors were encountered: