Skip to content
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

Finding a new way to run content scripts #23

Open
Eloston opened this issue Oct 17, 2015 · 1 comment
Open

Finding a new way to run content scripts #23

Eloston opened this issue Oct 17, 2015 · 1 comment
Assignees
Milestone

Comments

@Eloston
Copy link
Owner

Eloston commented Oct 17, 2015

The current method of running frame scripts has several problems:

  • window.postMessage can be picked up by scripts in the page (which is currently used to prevent the frame script from injecting twice into the page due to the way chrome.tabs.executeScript is run)
  • There's no way to get the mode without making additional asynchronous calls. It's important for the frame script to know the mode on initialization so it can know whether to stop autobuffering or not.

I've come up with three solutions that make use of content scripts declared in the manifest:

  • Send a message to the background page and run the sendResponse method (which I think runs synchronously) with the mode as an argument (or don't run it at all if the mode is "nothing".)
  • Run chrome.tabs.getCurrent and chrome.runtime.getBackgroundScript at the same time in the content script, and have both callbacks attempt to run a function in the background script to get the mode (based on the tab id.)
  • Have chrome.tabs.executeScript set a variable that the content script defined in the manifest file can read.

The question is, which method is fastest? Is there a faster method not listed above?

@Eloston
Copy link
Owner Author

Eloston commented Nov 21, 2015

I have settled on message passing via ports: https://developer.chrome.com/extensions/messaging#connect

It is a cleaner implementation and seems to be the recommended way to pass data between background and content scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant