google-chrome-extension

How do I get the URL for a dropped image using a Chrome userscript?

我怕爱的太早我们不能终老 提交于 2020-01-24 02:19:08
问题 In the following chrome user script, how can I get a url for an image that I drag from my desktop? Where I have the debugger line, I'm getting the empty string for e.dataTransfer.getData("text") and e.dataTransfer.getData("url") // ==UserScript== // @match http://*/* // @match https://*/* // ==/UserScript== function preventDrag(e) { e.stopPropagation(); e.preventDefault(); } function handleDrop(e) { console.log("Just dropped: " + e.dataTransfer.files[0].name); debugger // TODO: grab the url

How to open Browser_Action from content.js? Is it even possible?

被刻印的时光 ゝ 提交于 2020-01-24 01:52:27
问题 I am working on a chrome extension that allows users to open the browser_action by pressing a keystroke that THEY have assigned from the options-page . I would like to use document.onkeyup = function(){ Chrome.runtime.openPopup(); }; or something along those lines... I know that this Particular Extension API ( runtime. openPopup ) only functions for mozilla firefox . I am building this extension for Chrome & Opera so this is not an option for me. How might I go about this? Would it be through

Communication between contentscript, background and popup scripts

一曲冷凌霜 提交于 2020-01-24 00:48:11
问题 On sending side : i.e from contentscript. contentscript.js: <script> //some DOM code to obtain values to store in 'marks' array. //here I'm sending marks array to background.js. // 1) Am I sending it right? chrome.runtime.sendMessage(marks); </script> On receiving end : i.e in background script.* background.js: chrome.runtime.onMessage.addListener(function(MessageSender sender, function sendResponse){ /* 2) what should be here */ }); 3) here , how can I collect(store) the array variable

Chrome extension - Messaging with multiple ports

百般思念 提交于 2020-01-23 18:24:45
问题 In my extension, different content scripts connect to background.js to communicate with each other. The problem I'm having, is that when I receive a message on one port, I am not able to forward this information to the other port. The error I'm getting is: Error: Attempting to use a disconnected port object My code in background.js chrome.runtime.onConnect.addListener(function(port) { if(port.name === "menuport") { port.onMessage.addListener(function(msg) { console.log('BGJS from menuport')

Detect all images with Javascript in an html page

北慕城南 提交于 2020-01-23 18:00:26
问题 I am writing a chrome extension and I am trying to detect all images in a webpage. I am trying in my JS code to detect all images on a webpage, and by all I mean: Images that are loaded once the webpage is loaded Images that are used as background (either in the CSS or inline html) Images that could be loaded after the webpage is done loading, for instance, when doing a google image search it is easy to find all images, but once you click on one image to make it bigger, this image is not

How to get the current version of Chrome from an extension?

China☆狼群 提交于 2020-01-23 17:13:31
问题 I'm making a user-agent switcher for Chrome using the experimental API WebRequest, and I'd like to display the current user-agent used. For that, I have to get the current version of Chrome, but I don't find anything about that in the doc and I can't access to the "chrome://version" page due to security considerations. Do you have an idea to help me? 回答1: How about window.navigator.userAgent on your backgroundpage? 回答2: You can always use the good old navigator object ( navigator.userAgent is

chrome extension needs offline access from server side

梦想与她 提交于 2020-01-23 12:26:09
问题 I am building a chrome extension. I used chrome.identity.getAuthToken to get the access_token. This provided me the access_token at the client side ( browser ) . Now I want to pass this access_token to my server. I want to have offline access to granted APIs, I understand that for this I have to exchange it with the long-live-token and refresh token. Is there a secure way to pass access_token to server? Or should I use htttp post? Another way is to redirect the user to server to have both the

How not to inherit styles in a chrome extension content script

一世执手 提交于 2020-01-23 07:25:29
问题 I'm writing a Google Chrome extension that runs a content script on every page. In my content script, I inject a <div> with some <ul> and <li> children into the page. I specify a few styles for these elements in a stylesheet. But I've found that on some random pages my elements will inherit styles from those defined on the webpage since I haven't specified every single style property for my divs. What's the best way I can stop my injected elements from inheriting these styles? It seems to me

Trouble debugging content scripts in a chrome extension using require.js

送分小仙女□ 提交于 2020-01-23 02:05:25
问题 To load modules in the content scripts I'm using the following code (source http://prezi.com/rodnyr5awftr/requirejs-in-chrome-extensions/): require.load = function (context, moduleName, url) { var xhr; xhr = new XMLHttpRequest(); xhr.open("GET", chrome.extension.getURL(url) + '?r=' + new Date().getTime(), true); xhr.onreadystatechange = function (e) { if (xhr.readyState === 4 && xhr.status === 200) { eval(xhr.responseText); context.completeLoad(moduleName) } }; xhr.send(null); }; The trouble

How to load an external JavaScript inside an extension popup

不羁的心 提交于 2020-01-22 19:50:06
问题 I'm trying to build a page action extension and need to load an external JavaScript library from the popup (it needs to come from the external domain so that the correct cookies are sent). However I get this error message: Refused to load script from 'http://api.flattr.com/js/0.6/load.js?mode=auto' because of Content-Security-Policy. Is there any way around this? 回答1: Using scripts via plain HTTP is no longer allowed for security reasons. See this issue. From linked page: Yeah, we're no