google-chrome-extension

How to import ES6 modules in content script for Chrome Extension

做~自己de王妃 提交于 2021-02-20 10:01:25
问题 In Chrome 61 , support for modules in JavaScript was added. Right now I am running Chrome 63. I am trying to use import / export syntax in Chrome extension content script to use modules. In manifest.json : "content_scripts": [ { "js": [ "content.js" ], } ] In my-script.js (same directory as content.js ): 'use strict'; const injectFunction = () => window.alert('hello world'); export default injectFunction; In content.js : 'use strict'; import injectFunction from './my-script.js';

How to import ES6 modules in content script for Chrome Extension

≯℡__Kan透↙ 提交于 2021-02-20 10:01:02
问题 In Chrome 61 , support for modules in JavaScript was added. Right now I am running Chrome 63. I am trying to use import / export syntax in Chrome extension content script to use modules. In manifest.json : "content_scripts": [ { "js": [ "content.js" ], } ] In my-script.js (same directory as content.js ): 'use strict'; const injectFunction = () => window.alert('hello world'); export default injectFunction; In content.js : 'use strict'; import injectFunction from './my-script.js';

How can we overwrite navigator.getBattery()?

断了今生、忘了曾经 提交于 2021-02-19 09:07:20
问题 We are writing a chrome extension that returns a random battery level when the battery level is checked by a site running client-side code for fingerprinting reasons. Sample code that can be used by a site can be seen below. navigator.getBattery().then(function(battery) { console.log(battery.level); }); We are unable to find documentation regarding how the navigator.getBattery() method can be overwritten to accomplish the goal. The incomplete content-script.js can be seen below. var

How can we overwrite navigator.getBattery()?

廉价感情. 提交于 2021-02-19 09:06:50
问题 We are writing a chrome extension that returns a random battery level when the battery level is checked by a site running client-side code for fingerprinting reasons. Sample code that can be used by a site can be seen below. navigator.getBattery().then(function(battery) { console.log(battery.level); }); We are unable to find documentation regarding how the navigator.getBattery() method can be overwritten to accomplish the goal. The incomplete content-script.js can be seen below. var

Is there a work-around for allowing content/background scripts to execute while open in the chrome web store?

不问归期 提交于 2021-02-19 08:13:05
问题 I've been spending several long hours trying to figure out why my Chrome extension wasn't working as it should only to find that apparently the Google Chrome webstore does not allow extensions to do certain things while it's open. I've read this thread on SO, though it's 2 years old now and the solutions posted did not work for me: Chrome Extension Content Script on https://chrome.google.com/webstore/ I'm running Chrome version 41.0.2272.118 (64-bit) on OS X Yosemite. As one of the responses

Simulate a REAL HUMAN mouse click in pure javascript?

帅比萌擦擦* 提交于 2021-02-19 07:34:42
问题 I'm currently working on a chrome extension and the extension has to automate some process but in the page when I click the element some action performed but when I click the element programmatically with JavaScript nothing happens. Does anyone know how to click it like real human ? event.isTrusted // readonly property but how can i make it as a event.isTrusted = true? I think the website made some prevention method with the isTrusted property of the click event! 回答1: From this answer: Try

Chrome webRequest onCompleted: Size of the page

☆樱花仙子☆ 提交于 2021-02-19 07:31:30
问题 I am working on a Chrome Extension, and I wanted to know if there was a way to know the amount of data which has been downloaded while loading a page. For example, if the user activates the extension, and goes on Google.com, I want to show him the size of the page: google.com. Is there a way to do this? Thanks! 回答1: There are a multitude of ways you could determine the size of a page using just javascript. You could manually calculate the size of the page by counting the ammount of characters

Callback of chrome.tabs.create is not triggered in a popup?

戏子无情 提交于 2021-02-19 05:57:08
问题 I am writing my first chrome extension, which should open an URL in a new tab and after that do something. manifest: { "manifest_version": 2, "name": "Test", "description": "", "version": "1.0", "browser_action": { "default_icon": "icon.png", "default_popup": "popup.html" }, "permissions": [ "tabs", "activeTab" ] } script.js: function toggle() { chrome.tabs.create({ url: "http://google.com" }, function(tab) { alert("Hello!"); }); } document.getElementById('toggle').addEventListener('click',

Chrome extension screenshot partial image cropping for Retina Display

扶醉桌前 提交于 2021-02-19 02:53:48
问题 I made a chrome extension, which captures a single element (div) of a website. I used chrome.tabs > captureVisibleTab to make a screenshot. Then, with the coordinates (x/y) and sizes (width/height) of the element (div) I crop the screenshot. This works fine for me on non-retina displays. But not so on a Macbook with Retina display. For example, on www.247activemedia.com, we want to capture the header div with the logo (id="header"). On non-retina result is: On a Macbook with Retina display:

Porting Chrome extension to Firefox : equivalent to chrome.storage

强颜欢笑 提交于 2021-02-19 01:25:52
问题 I'm trying to port Chrome extension to Firefox and I would like to know what's the equivalent to chrome.storage.local.set and chrome.storage.local.get in Firefox add on sdk. I think, it's simple-storage . Here is my code : chrome.storage.local.set({'tokenFU': token}); [...] chrome.storage.local.get('tokenFU',function(result){ token=result.tokenFU; if(token && token != 'undefined'){ hideLog(); } else showLog(); }); Thanks in advance ! 回答1: Yes exactly, it is simple-storage. You can use it like