google-chrome-extension

List file sizes of all images on a page (Chrome Extension)

爷,独闯天下 提交于 2019-12-17 14:28:46
问题 I want to write a Chrome Extension where you enter a page URL and it lists all the image filenames that appear on that page with the file sizes of those images e.g. "Page contains images: 1.jpg (65KB), 2.png (135KB)". How can this be done? I want to avoid making this a devtools extension as well. I've tried using the webRequest API but I can see no way to access the body of the requests. The image size might be sent in the response header but this isn't guaranteed. I've tried using AJAX to

Prevent window.open from focusing

老子叫甜甜 提交于 2019-12-17 11:50:24
问题 I want to open a page in a new tab in Google Chrome with window.open(), but I don't want that window to gain focus after it's opened, but to stay in the background. Is this possible? It only has to work on Google Chrome. It can also use the Google Chrome extension API. Thanks 回答1: The proper way would be to use extension API: chrome.tabs.create({url: "http://...", selected: false}); Code should be placed in a background page. If you need it inside a content script you can pass a message to a

How do I log out of a chrome.identity oauth provider

橙三吉。 提交于 2019-12-17 11:44:12
问题 I'm using chrome.identity to log into a 3rd party oauth provider in an chrome extension. It works fine for logging in- when I use launchWebAuthFlow I am presented with the third party login screen and redirected back to my application after the signin flow. However, I can't find a way to enable log out functionality in my extension. There doesn't seem to be a function to clear the cached logged in identity. The next time that launchWebAuthFlow is called, it will automatically log me in as the

Is it possible to get an Id token with Chrome App Indentity Api?

感情迁移 提交于 2019-12-17 10:49:32
问题 I can't get a user's id_token (https://developers.google.com/accounts/docs/CrossClientAuth) from the Chrome identity api (https://developer.chrome.com/apps/identity). I can get an access_token using the chrome identity sample when the oauth section in the manifest is: "oauth2": { "client_id": "<chrome-app-client-id>.apps.googleusercontent.com", "scopes": ["https://www.googleapis.com/auth/plus.login"] } But when I try to get the id_token the same way I get it on my android client a get the

Javascript textarea undo redo

此生再无相见时 提交于 2019-12-17 10:46:13
问题 I'm making a small javascript editor (for a chrome extension) somewhat like the one on SO. There's a toolbar for manipulation of the text in the textarea. (e.g. surround the selected text with some template) I was wondering if there is a easy way to achieve this, currently when using the system undo/redo, it messes the text up (I think the system is only keeping track of deltas between edits). 回答1: You can probably simulate textInput events to manipulate the contents of the textarea. The

XMLHttpRequest: Multipart/Related POST with XML and image as payload

…衆ロ難τιáo~ 提交于 2019-12-17 10:42:21
问题 I'm trying to POST an image (with Metadata) to Picasa Webalbums from within a Chrome-Extension. Note that a regular post with Content-Type image/xyz works, as I described here. However, I wish to include a description/keywords and the protocol specification describes a multipart/related format with a XML and data part. I'm getting the Data through HTML5 FileReader and user file input. I retrieve a binary String using FileReader.readAsBinaryString(file); Assume this is my callback code once

Chrome extension: how to pass ArrayBuffer or Blob from content script to the background without losing its type?

断了今生、忘了曾经 提交于 2019-12-17 10:29:24
问题 I have this content script that downloads some binary data using XHR, which is sent later to the background script: var self = this; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = 'arraybuffer'; xhr.onload = function(e) { if (this.status == 200) { self.data = { data: xhr.response, contentType: xhr.getResponseHeader('Content-Type') }; } }; xhr.send(); ... later ... sendResponse({data: self.data}); After receiving this data in background script, I'd like to form

Run script each time Chrome extension icon clicked

天大地大妈咪最大 提交于 2019-12-17 10:15:32
问题 How do I write a chrome extension such that every time a user clicks the icon, my script is run but no popup is opened? (I would look this up in the docs myself but for whatever reason they suddenly stopped working, 404ing every page, as I got to this point). I'm assuming it's just setting up the manifest correctly. Here's what I have now: { "name": "My Extension", "version": "0.1", "description": "Does some simple stuff", "browser_action": { "popup" : "mine.html", "default_icon": "logo.png"

google chrome extension :: console.log() from background page?

梦想的初衷 提交于 2019-12-17 10:09:33
问题 If I call console.log('something'); from the popup page, or any script included off that it works fine. However as the background page is not directly run off the popup page it is not included in the console. Is there a way that I can get console.log() 's in the background page to show up in the console for the popup page? is there any way to, from the background page call a function in the popup page? 回答1: Any extension page (except content scripts) has direct access to the background page

chrome.tabs.executeScript(): How to get result of content script?

天大地大妈咪最大 提交于 2019-12-17 09:57:42
问题 According to the documentation for chrome.tabs.executeScript (MDN), the callback function accepts an "array of any result" result set from the execution of the script(s). How exactly do you use this to get results? All of my attempts end up with undefined being passed to the callback. I have tried returning a value at the end of my content script, which threw a Uncaught SyntaxError: Illegal return statement . I tried using the optional code object argument {code: "return "Hello";} with no