I am currently using jQuery $ .getScript in my content script so that my JavaScript files are in my content script Able to import. It works very well to import all of my javascript files, but I'm running into a problem where I can not use chrome. Runtime. Message to communicate with my background scripts within imported JavaScript files, possibly because the function is not recognized by a script that is processed by $ .getScript (please correct me if I am wrong) .
content.js (direct injection through the manifest file), I have the following code:
$ GetScript (chrome.extension.getURL ('js / angular-1.2.26-min.js'), function (data) {$ .getScript (Chrome.extension.getURL) (function) (data) {$ .getScript (chrome) .extension.getURL ('app / overview / overview-controller.js'), function (data) {$ .getScript (chrome.extension.getURL ('js / angular-bootstrap.js'), function (data) {} }}}}}}
and inside app /app.js (or any file in the injection), I can put anywhere a send message call I try but nothing NT (I log in to the message event listener in the background)
chrome.runtime.sendMessage ({msg: 'test'}, function (response) {alert ('done'}}) / Code> Note: I have tried to import javascript files by sending a message to the background script to use chrome.tabs.executeScrip instead, but I have only a specific time And in a specific frame, so that he does not help I Also try to use, but it seems that it is not working. I ran in block execution in "{{URL}} 'because the frame of the document is the sandbox and permission for' permission-script 'is not set" My questions: < / P>
-
Is an effective solution to use Chrome. The message inside the Runtime.endend script which is injection using $ .getScript?
-
Is there a way to use executescript inside the content script?
-
Is there any effective way to include content in a particular frame? Again, from the top - I tried a third party library, but participated in a problem about the sandboxing of the frame, but it is weird because I clearly used it on the script while using the manifest I'm able to inject content scripts.
Thank you!
Well, that's an interesting question.
Most of the methods & lt; Script & gt;
rely on injection, which adds code to the wrong page (page), which does not have access to the Chrome API. I think how it is $ GetScript
works, therefore, it will not work for purpose.
Another method is using eval ()
. According to, eval ()
is allowed (but disappointed) in content scripts. So in theory, XHR / jQuery AJAX can load the script file in the request and then eval ()
its content it should work.
Finally, you can modify your content script only to execute if some condition is completed (say, a variable is set), and therefore in all frames Injection one tab should be less than one problem. This may possibly be messy though. Note that the content script, which can be useful
Comments
Post a Comment