Access chrome extension from a web app
I wonder if anybody can lay out the general logic of what I should do to achieve the following:
I h开发者_StackOverflow社区ave an extension for Chrome, that gets a list of user's bookmarks.
When user visits web page, the information that was retrieved by extension is accessed and displayed on web page.
I already have an extension, I wonder how do I access it from a web page?
To communicate with a web page you need a content script that will load on that page. Then you can then use events to communicate. The content script can receive messages from your background page and forward them to the web page if necessary.
Make sure that you take the security considerations section to heart. You make user's bookmarks available to a web page, you should be very certain that this web page should have access to them.
So, if the author of the extension wrote the extension, and sandboxed his code (this means that he/she did something to keep his vars out of the global namespace), then there isn't much that you are going to be able to do. So... check to see if the author left his variables accessible at the global namespace level. To do this in Chrome, go to the page, open the Dev Tools, go to the console and type
console.log(window);
This will show you the global namespace, and should show you what you are looking for. If you see anything that doesn't look like a traditional variable or object or function, then that is something you should investigate. I wish I could give you clearer steps here, but you are essentially trying to hijack the code from the extension, and that kind of stuff takes a lot of testing/investigating.
If there isn't anything abnormal in the global namespace, then that means that the code is sandboxed, and you are in a tough spot. It will be tough for you to get any of the vars/values/objects from the extension code.
Good luck.
精彩评论