Questions tagged [google-chrome-extension]

Extension development for the Google Chrome web browser. You write them using web technologies such as HTML, JavaScript, and CSS.

This tag is dedicated to questions about extension development for the Google Chrome web browser.

The Chrome extension API is documented here.

Absolute beginners should start here.

A good tutorial video by official Google Developers is available on YouTube

Overview of extension architecture can be read here.

The What's New page lists some of the recent changes to the extension APIs, while the Official Chrome Releases Blog announces new releases of Chrome and Chrome OS. For general updates on the browser, visit the Official Chrome Blog.

Troubleshooting

Before posting a question, make sure that you've read the API documentation. If some methods are not documented, it may be because they are deprecated.

If necessary, include relevant parts of your manifest.json file in the question.

A common source of errors is the misunderstanding of manifest version 2 and Content Security policy (CSP). Read the documentation for the CSP to see if it answers to your question.

For anything not related to development of Chrome extensions, such as issues with publishing in the Chrome Web Store, browse the Chromium-extensions Google group (now read-only). Extension authors with questions about the Chrome Web Store can contact the cws-developer-support team at https://support.google.com/chrome_webstore/contact/developer_support/.

Migration to Manifest Version 3

Manifest version 3 is now in support since chrome 88, and will be allowed on the chrome webstore on January 2021. It is recommended to read how to migrate from v2 to v3 and an overview of the new features are found here.

29271 questions
65
votes
7 answers

Can the window object be modified from a Chrome extension?

I would like to make a Chrome extension that provides a new object inside window. When a web page is viewed in a browser with the extension loaded, I would like window.mything to be available via Javascript. The window.mything object will have some…
Zach Rattner
  • 20,745
  • 9
  • 59
  • 82
65
votes
2 answers

How to inject CSS using content script file in Chrome extension?

I'm trying to inject my CSS from JavaScript which is injected as content script: "content_scripts": [ { "matches": ["http://www.google.com/*"], "js": ["script.js"] } ], I found similar question about injecting CSS, but I…
Roman
  • 5,358
  • 9
  • 34
  • 43
64
votes
1 answer

Chrome extension code vs Content scripts vs Injected scripts

I am trying to get my Chrome Extension to run the function init() whenever a new page is loaded, but I am having trouble trying to understand how to do this. From what I understand, I need to do the following in background.html: Use…
Jon
  • 2,249
  • 6
  • 26
  • 30
64
votes
9 answers

String compression in JavaScript

I'm looking for a JavaScript function that given a string returns a compressed (shorter) string. I'm developing a Chrome web application that saves long strings (HTML) to a local database. For testing purposes I tried to zip the file storing the…
Bambax
  • 2,920
  • 6
  • 34
  • 43
64
votes
8 answers

chrome.runtime.onMessage response with async await

I want to use async await in an onMessage listener: chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) =>{ var key = await getKey(); sendResponse(key); }); However I get undefined when I send a message. From the…
Chris
  • 13,100
  • 23
  • 79
  • 162
64
votes
9 answers

Using chrome extension apis in typescript

I'm building a chrome extension written in TypeScript. I'm using WebStorm and I added the chrome-DefiniteltyTyped library in my project. However, when I write this in my typescript code : chrome.extension.getURL I got an error : cannot find name…
64
votes
2 answers

window.localStorage vs chrome.storage.local

I'm developing a Chrome extension and I need to store some data and then get it in some point. I did investigation on available storages and came across to the following ones: window.localStorage and chrome.storage.local. So my question is, which…
64
votes
7 answers

saving and retrieving from chrome.storage.sync

I am trying to save a data object in chrome sync storage and then retrieve it, however the get() function always returns an empty object. The code I am using is, function storeUserPrefs() { var key='myKey', testPrefs = {'val': 10}; …
source.rar
  • 8,002
  • 10
  • 50
  • 82
63
votes
9 answers

Chrome extension; open a link from popup.html in a new tab

I'm doing a Chrome extension and I got helped in this post here. My problem now is how to open a new tab of chrome that has as URL the link I clicked in the popup.html. I tried to do like someone suggested in their answers in other similar question…
Advicer
  • 1,300
  • 1
  • 14
  • 26
63
votes
3 answers

How to detect the installed Chrome version?

I'm developing a Chrome extension and I'm wondering is there a way that I can detect which version of Chrome the user is using?
Skizit
  • 43,506
  • 91
  • 209
  • 269
63
votes
3 answers

What does "http://*/*", "https://*/*" and "" mean in the context of Chrome extension's permissions

I am trying to understand the working of Google chrome extensions. I was studying the manifest.json file where I came across the permissions "http://*/*", "https://*/*" and "" Can anybody explain what do these permissions mean?
TheRookierLearner
  • 3,643
  • 8
  • 35
  • 53
62
votes
11 answers

Copy to Clipboard in Chrome Extension

I'm making an extension for Google Chrome and I have hit a snag. I need to copy a readonly textarea's content to the clipboard on click in the popup. Does anyone know the best way to go about this with pure Javascript and no Flash? I also have…
Kyle Ross
  • 2,090
  • 4
  • 20
  • 27
61
votes
5 answers

Chrome Extension - How to get HTTP Response Body?

It seems to be difficult problem (or impossible??). I want to get and read HTTP Response, caused by HTTP Request in browser, under watching Chrome Extension background script. We can get HTTP Request Body in this…
otiai10
  • 4,289
  • 5
  • 38
  • 50
61
votes
7 answers

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'"

Im creating a chrome extension for Rss reader in that im getting the above error. please help manifest.json { "name": "Tutorialzine Extension", "manifest_version": 2, "version": "1.1", "description": "Making your first Google Chrome…
61
votes
6 answers

How can I open my extension's pop-up with JavaScript?

I am trying to write a JavaScript function that will open my extension like when the extension icon is clicked. I know how to open my extension in a new tab: var url =…
Yuqing Huang
  • 785
  • 2
  • 7
  • 7