content-script

Undefined response from content script in chrome extension

安稳与你 提交于 2019-11-30 04:59:25
问题 I can't get a response from my content script to show up in my popup.html. When this code runs and the find button is clicked, "Hello from response!" prints, but the variable response is printed as undefined. The ultimate goal is to get the current tab's DOM into my script file so that I can parse through it. I'm using a single time message to a content script to get the DOM, but it's not being returned and is showing up as undefined. I'm looking for any help possible. Thanks. popup.html: <

My injected <script> runs after the target-page's javascript, despite using run_at: document_start?

守給你的承諾、 提交于 2019-11-29 17:06:45
问题 I am having some problem with the order of javascript execution when I use the content script to inject some javascript into the HTML page: This is my HTML page I use to test, test.html : <html><head> <title>Test Page</title></head> <body> <script> console.log("In page"); </script> </body> </html> This is the javascript I use to inject additional code into HTML page, injector.js : var s = document.createElement("script"); s.src = chrome.extension.getURL("inject.js"); document.documentElement

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

元气小坏坏 提交于 2019-11-29 17:06:24
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).ready(function () {/*cool stuff here, that require content*/}); } var event = new CustomEvent(

From a browser action popup: open a new tab and fill input fields

只愿长相守 提交于 2019-11-29 16:47:39
I'm trying to build a basic Chrome extension that, from a browser action popup, opens a website in a new tab, and fills in the login credentials. I can get the Chrome extension to open the new page but can't seem to get it to input text into the input fields. Manifest.json { "manifest_version": 2, "name": "Vena", "description": "This extension will allow users to login to vena accounts", "version": "1.0", "browser_action": { "default_icon": "images/icon.png", "default_popup": "popup.html" }, "permissions": [ "activeTab" ] } popup.html <!doctype html> <html> <head> <title>Auto-Login</title>

Chrome Extension: How to detect if an extension is installed using Content Scripts

你说的曾经没有我的故事 提交于 2019-11-29 16:08:28
I am asking this question after looking at several related questions on stackoverflow. I started with how to detect if an extension is installed . I opted for the method where I add a div to body using content scripts on some pages. Here is how I did it... manifest.json { "name": "Install Check", "content_scripts": [ { "matches": ["http://host.com/*"], "js" : ["insert_node.js"] } ], "permissions": [ "tabs", "host.com/*" ] } insert_node.js (content script) var insert_node = document.createElement('div'); insert_node.id = "HOST_SITE"; document.body.appendChild(insert_node); host page <html>

Is that possible calling content script method by context menu item in Chrome extension?

十年热恋 提交于 2019-11-29 14:40:55
问题 I'm trying to use context menu item to invoke my method written in content script. Is that possible? As i have tried, context menu could only doing stuff in backend. E.g. // A generic onclick callback function. function genericOnClick(info, tab) { console.log("item " + info.menuItemId + " was clicked"); console.log("info: " + JSON.stringify(info)); console.log("tab: " + JSON.stringify(tab)); } // Create one test item for each context type. var contexts = ["page","selection","link","editable",

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

末鹿安然 提交于 2019-11-29 11:30:36
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. 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.documentElement.appendChild(s); s.parentNode.removeChild(s); // Just to clean-up. 来源: https://stackoverflow

Options-enabled content-script Chrome extension without background page?

非 Y 不嫁゛ 提交于 2019-11-29 08:18:13
I'm making a content script extension for Google Chrome, it adds functionality to a website's page. I want to add a couple of options, not big deal really, I'd just need two strings (none of which are sensitive user data). From this answer , I assume I need a background page, which I'd rather not add to my extension - I don't want it to gain unnecessary weight. Do I really need a background page, or I could have an options page without it (and which storage could I use)? UPDATE As of Chrome 20 you can now use the Storage api..... http://code.google.com/chrome/extensions/storage.html Old way

How to load a content script on all Google (international) pages?

天大地大妈咪最大 提交于 2019-11-29 07:07:15
For a Google-Chrome extension, I would like to load a content script on all Google pages. What is the best way to do this? I tried this, in the manifest.json , but it does not work: "matches": ["http://www.google.*/*", "https://www.google.*/*"], This "works" but it is a bit long to write and I do not think it is the best practice: "matches": ["http://www.google.com/*", "https://www.google.com/*", "http://www.google.fr/*", "https://www.google.fr/*", "http://www.google.de/*", "https://www.google.de/*", etc..."], See Match patterns and globs . Unfortunately, Google-Chrome doesn't have a nice

Clipboard Copy / Paste on Content script (Chrome Extension)

笑着哭i 提交于 2019-11-28 21:35:55
I am using a Content script to manipulate data in the DOM. I have been using document.execCommand('copy'); successfully on a popup page. I am now searching for a way to make it work on a Content script. I have checked the limitations for content scripts here , but I do not understand if Clipboard control is limited or not. I have also checked answers here - in stackoverflow, but it seems that most are uncertain and some are from a few years ago so there might have been changes. Even if it is limited, is it possible to have some kind of workaround? Thank you! I am posting the current script