google-chrome-extension

How I can close all tabs in Google Chrome window using API

时光总嘲笑我的痴心妄想 提交于 2019-12-24 01:44:34
问题 I need close all tabs in Chrome window via my extension. What is the best practice now? How would you have done? 回答1: In your background page, use chrome.tabs.query(...) to get all tabs, then call chrome.tabs.remove(...) to close that, code will look like: chrome.tabs.query({}, function (tabs) { for (var i = 0; i < tabs.length; i++) { chrome.tabs.remove(tabs[i].id); } }); 回答2: You can only close windows/tabs that you create yourself. That is, you cannot programmatically close a window/tab

chrome.desktopCapture - can't record both system audio and microphone?

倖福魔咒の 提交于 2019-12-24 01:37:08
问题 I've built a Chrome extension that captures screen activity and microphone input and outputs a video file. Since chrome.desktopCapture can't record audio input alongside screen capture, I'm getting the mic in its own, separate stream. So: //get screen stream chrome.desktopCapture.chooseDesktopMedia(['screen'], null, (stream_id, opts) => { let constraints = {video: mandatory: { chromeMediaSource: 'desktop', chromeMediaSourceId: stream_id }}; navigator.mediaDevices.getUserMedia(constraints)

captureVisibleTab of non-visible tab

主宰稳场 提交于 2019-12-24 01:16:44
问题 Is it possible to take a screenshot of non-visible tab with chrome extension API? chrome.tabs.captureVisibleTab takes only the selected tab on a specific window. I could programmatically switch to the needed tab, take a screenshot and switch back, but since it's all async, there's a flicker while it happens. 回答1: Copy the page to a new window and move the window outside the screen then take a screenshot. Then the user will not notice that you have opened a new window because it is outside the

Prevent popup.html of Chrome from being closed by iframe action

微笑、不失礼 提交于 2019-12-24 01:16:24
问题 I embedded an iframe in my popup.html of my extension. Inside this iframe the use has to submit by clicking on a button. This opens a new tab which causes my popup.html to be closed. How can I force the popup.html to remain active? This is necessary as the iframe processes with more information. My popup.html: http://pastebin.com/QftvfQ8c 回答1: You can not force a popup to remain open. 来源: https://stackoverflow.com/questions/8935475/prevent-popup-html-of-chrome-from-being-closed-by-iframe

chrome.tabs.executeScript only fires when the Developer Console is open

妖精的绣舞 提交于 2019-12-24 00:56:21
问题 I'm trying to make an auto-login button extension for chrome. My code is the following: options.html: function gotoAdmin(){ chrome.tabs.create({'url': "http://www."+currentTabDomain+"/admin"}, function(tabId,changeInfo,tab) { chrome.tabs.executeScript(null, {file: "login.js"}); }); } ... <img src="admin.png" onClick="gotoAdmin()"> login.js: $(document).ready(function(){ $('input[name=username]').val('foo'); $('input[name=password]').val('bar'); $('#form').submit(); }); manifest.json:

Chrome extension code no longer running when tab inactive?

我们两清 提交于 2019-12-24 00:54:08
问题 I created a very simple Chrome extension for personal use that sent me a browser notification if a DOM element changed in a tab that had a specific site open and switch that tab to be the active one. It would work if the tab was not active and open (intended/wanted behavior), but recently the notification no longer sends unless the tab is active. I haven't changed any of the code, so not sure if a recent Chrome update changed the behavior of the API. Here's my code: manifest.json { "name":

How to get window id of the popup window that is created by chrome.windows.create()

ぐ巨炮叔叔 提交于 2019-12-24 00:53:02
问题 How to get window-id of the popup window that is created by chrome.windows.create() background.html window_options={ "url":"another_popup.html" "type":"popup" }; chrome.windows.create(window_options,call_back_function) call_back_function(Window window) { console.log(window.id) //prints the window's id properly } another_popup.html(the page that the popup window holds) $(document).ready(function() { console.log(window.id) //says ,cannot find property and gives a null }); 回答1: There is no such

Refresh after a timer of 5000 seconds and print the alert

社会主义新天地 提交于 2019-12-24 00:47:29
问题 I am making a chrome extension to keep refreshing a page unless stop button is chosen. But i am able to do it only once. Here is my code for background.js chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { switch(request.type) { case "table-row-count_start": alert("Refershing started"); RefreshAndCount(); break; case "table-row-count_stop": alert("Stop Refershing"); break; } return true; }); var RefreshAndCount = function() { chrome.tabs.query({active: true,

How do I test a context menu entry in a Chrome Extension?

做~自己de王妃 提交于 2019-12-23 23:34:55
问题 I have a Chrome extension that adds an entry to the browser's context menu, that allows a user to copy the top-level heading of a page to the clipboard. Example: Given the following HTML: <h1>My Page</h1> Right clicking on the page, selecting Plugin Name > Copy Title , will copy the string "My Page" to the clipboard. This should only work on a specified domain. I'd like to write tests to ascertain that: The context menu entry only appears on the specified domain When on the specified domain,

Display global page object from contentscript to popup in chrome extension

 ̄綄美尐妖づ 提交于 2019-12-23 23:12:11
问题 I have an object WIO on a webpage which i want to access in my chrome extension . I have followed this example and injected my script.js in the page using first method. I can successfully read WIO object in script.js. But the problem is i can't access it in popup.html. Any suggestions will be great appreciated. Here is manifest.json { "manifest_version": 2, "name": "Campaign Analyzer", "description": "Analyze campaign data", "version": "0.1", "icons": { "128": "icon_128.png" }, "browser