content-script

execute a function in content script if response is sent from Background

浪尽此生 提交于 2019-12-02 18:12:23
问题 For my Chrome extension, I am attempting to post selected text to a PHP webpage. A solved question on this website (Chrome Extension: how to capture selected text and send to a web service) has helped me a lot in achieving this, but I want a different way of posting the text. Instead of XMLHttpRequest as mentioned there, I want to send a hidden JS form from the content script. This method allows me to view or change the text before importing it to the database. The problem is to get the

Chrome Extension API: chrome.tabs.captureVisibleTab on Background Page to Content Script

故事扮演 提交于 2019-12-02 01:29:48
My overall goal was to take a screenshot via the background page using: http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab and pass it to the content script so I can use the page's HTML DOM to analyze the screenshot and cut it up the way I would like. However, I can't seem to pass the dataUrl back to the content script with Message Passing: http://developer.chrome.com/extensions/messaging.html I tried JSON.stringify() but to no avail. This works perfectly fine: background.js chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { sendResponse(

Chrome content script does not load in about:blank page

半腔热情 提交于 2019-12-01 20:21:03
问题 I am developing a Chrome extension which will load content script according to the following manifest: "content_scripts" : [ { "matches" : [ "<all_urls>" ], "js" : [ "scripts/namespace/namespace.js", "scripts/log/Logger.js"] "run_at" : "document_start", "all_frames" : true } ] There is a mockup site whose HTML is: <html> <head> <script language=javascript> var test; function makewindow() { test=window.open('mywin'); test.window.document.write("<html><body><A onclick=window.close(); href= >

Chrome content script does not load in about:blank page

霸气de小男生 提交于 2019-12-01 18:24:08
I am developing a Chrome extension which will load content script according to the following manifest: "content_scripts" : [ { "matches" : [ "<all_urls>" ], "js" : [ "scripts/namespace/namespace.js", "scripts/log/Logger.js"] "run_at" : "document_start", "all_frames" : true } ] There is a mockup site whose HTML is: <html> <head> <script language=javascript> var test; function makewindow() { test=window.open('mywin'); test.window.document.write("<html><body><A onclick=window.close(); href= > click Me to Close</A>"); test.window.document.write(" ---- </body></html>"); } </script> </head> <body>

Is it possible to have two content scripts run on two separate pages?

有些话、适合烂在心里 提交于 2019-12-01 13:28:08
Say I have two content scripts, codeA.js and codeB.js . I am wondering if it possible to run codeA.js on http://www.example.com and have codeB.js run on http://www.domain.com . Would it be possible to set my content_scripts in the manifest.json file to: "content_scripts": [ { "matches": ["http://www.example.com", "http:www.domain.com"], "js": ["codeA.js", "codeB.js"] } ] and then have each script check to see which URL the page currently sits at? If so, how would I go about doing this? UPDATE: I have tried using the following code if(document.location == "http://*.google.com/*" || "https://*

Is it possible to have two content scripts run on two separate pages?

拥有回忆 提交于 2019-12-01 11:36:41
问题 Say I have two content scripts, codeA.js and codeB.js . I am wondering if it possible to run codeA.js on http://www.example.com and have codeB.js run on http://www.domain.com. Would it be possible to set my content_scripts in the manifest.json file to: "content_scripts": [ { "matches": ["http://www.example.com", "http:www.domain.com"], "js": ["codeA.js", "codeB.js"] } ] and then have each script check to see which URL the page currently sits at? If so, how would I go about doing this? UPDATE:

Undefined response from content script in chrome extension

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 20:29:53
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: <!DOCTYPE html> <html> <body> <head> <script src="script.js"></script> </head> <form > Find: <input id=

Why is chrome.cookies undefined in a content script?

狂风中的少年 提交于 2019-11-30 13:46:06
Whenever I try to read from a cookie using the chrome.cookies.get() function I get this error: TypeError: Cannot read property 'get' of undefined. I am calling the function in my content.js file, and it will only run on twitter.com(that part works). Here is my manifest file: { "manifest_version": 2, "name": "Twitter-MultiSignin", "description": "twiter sign in", "version": "1.0", "permissions": [ "cookies", "alarms" , "http://*/*", "https://*/*", "storage"], "content_scripts": [{ "matches": ["http://twitter.com/*","https://twitter.com/*"], "js": ["jquery.js","content.js"] }], "browser_action":

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

我的未来我决定 提交于 2019-11-30 11:23:26
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.appendChild(s); console.log("Inject finished"); And this is the content of injected script, inject.js :

How to transfer data between the content scripts of two different tabs?

旧城冷巷雨未停 提交于 2019-11-30 07:36:42
In my extension I need to transfer some data from one tab's content script to another tab's content script. How can I choose certain tab using chrome.tabs, if I know a part of that tab object's name or url in it? How can two tabs' scripts communicate? UPDATE: Apparently I don't have method sendMessage in chrome.extension. When I run the following from content script: chrome.extension.sendMessage("message"); I get in console: Uncaught TypeError: Object # has no method 'sendMessage' First, note that messages passed within an extension are JSON-serialized. Non-serializable types, such as