content-script

How to pass data from content-script to page-level?

前提是你 提交于 2020-01-20 08:42:13
问题 I'm injecting all my js code to front page, but it needs pictures for ui and stuff, that can be imported only with the help of chrome.extension.getUrl and can be called only from content-script, so I've found tons of advices how to pass data to content page, and nothing of about how pass data back, is it possible at all? My code now looks like this: my js code, that will be injected with other code: var Content = {}; $(document).contentReady = function(content) { Content = content; $(document

Is it possible to run a script in context of a webpage, before any of the webpage's scripts run, using a chrome extension?

不羁岁月 提交于 2020-01-20 06:58:28
问题 I have tried "run_at": "document_start" , but there is no DOM when the extension gets control, so I can not insert the script into head . Also, tried to use DOMNodeInserted , but it is not fired for head . if I try to insert the script on first DOMNodeInserted event, it gets executed after the webpage's scripts. 回答1: The root element always exist. You can just append the <script> to the <html> element: var s = document.createElement('script'); s.textContent = 'console.log("Test");'; document

waitForKeyElements(); - Stop a script firing on a popup in Chrome Extension?

一个人想着一个人 提交于 2020-01-16 18:13:15
问题 This question is a follow-on to another question which needed asking and warranted a new post, so excuse me if I refer to things which may not be clear without reading the other question. When using the utility waitForKeyElements() I'm facing an issue in which a div is included inside a small popup contained within the same URL. My extension is currently running on the Twitter site, and my intention is that a div contained on the profile pages (e.g. http://twitter.com/todayshow) gets moved

How to access localStorage in extension background page?

好久不见. 提交于 2020-01-15 12:20:40
问题 I have a chrome extension that sets a string value in JavaScript localStorage in a content script. I have tested that it is being set by grabbing it and displaying it. While on the same page after it has loaded I can still access the stored string in the javascript console. If I go to any other tabs js console or when I try to access it in my other extensions background page(After the browser action has been clicked) it is returning null. extension 1 contentscript.js embeded.addEventListener

Binding extension content scripts to Chrome's start page?

牧云@^-^@ 提交于 2020-01-15 12:15:06
问题 Is there any way to bind a content script to Chrome's start page? I tried setting matches to "*" , but it doesn't even run. With "*://*/*" it does not bind. 回答1: No, you cannot*. Technically, the start page is chrome://newtab/ , and Chrome Extensions cannot access chrome:// pages for security reasons, not even with the widest "<all_urls>" permission. Your only hope is to make your own New Tab page, though it would be hard to replicate all of the default functionality (e.g. thumbnails of top

Binding extension content scripts to Chrome's start page?

…衆ロ難τιáo~ 提交于 2020-01-15 12:15:05
问题 Is there any way to bind a content script to Chrome's start page? I tried setting matches to "*" , but it doesn't even run. With "*://*/*" it does not bind. 回答1: No, you cannot*. Technically, the start page is chrome://newtab/ , and Chrome Extensions cannot access chrome:// pages for security reasons, not even with the widest "<all_urls>" permission. Your only hope is to make your own New Tab page, though it would be hard to replicate all of the default functionality (e.g. thumbnails of top

Access chrome local storage used in both content script and popup?

人盡茶涼 提交于 2020-01-07 01:22:50
问题 I'm designing my first chrome extension and have run into a problem. On my popups.js users can enter words and definitions that are saved as an array in chrome storage: function save() { chrome.storage.local.set({'words': words}); chrome.storage.local.set({'definitions': definitions}); } I would like to then load these words and definitions in my content script js like so: function load() { //load words from local storage chrome.storage.local.get('words', function (result) { if (result.words

How to download a file via a Chrome Content Script?

好久不见. 提交于 2020-01-02 09:28:33
问题 This SO answer details how to download a file via a Chrome Extension, but I am using a Content Script, which has limited access to Chrome's APIs. In other words, I don't have access to the chrome.downloads object. I also tried this vanilla JS solution, but it did not work for me. Does anyone have a solution for Content Scripts or know why the second solution doesn't work? 回答1: Write a background page or event page and do it from there using the example in your linked answer. Communicate from

Hijacking a variable with a userscript for Chrome

只愿长相守 提交于 2019-12-29 03:34:13
问题 I'm trying to change the variable in a page using a userscript. I know that in the source code there is a variable var smilies = false; In theory I should be able to change it like that: unsafeWindow.smilies = true; But it doesn't work. When I'm trying to alert or log the variable to the console without hijacking I get that it's undefined. alert(unsafeWindow.smilies); // undefined !!! EDIT: I'm using Chrome if it changes anything... http://code.google.com/chrome/extensions/content_scripts

Chrome extension content script re-injection after upgrade or install

守給你的承諾、 提交于 2019-12-28 01:43:54
问题 After the Chrome extension I'm working on is installed, or upgraded, the content scripts (specified in the manifest) are not re-injected so a page refresh is required to make the extension work. Is there a way to force the scripts to be injected again? I believe I could inject them again programmatically by removing them from the manifest and then handling which pages to inject in the background page, but this is not a good solution. I don't want to automatically refresh the user's tabs