Skip to content

Instantly share code, notes, and snippets.

@dotproto
Created November 15, 2019 21:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dotproto/3a328d6b187621b445499ba503599dc0 to your computer and use it in GitHub Desktop.
Save dotproto/3a328d6b187621b445499ba503599dc0 to your computer and use it in GitHub Desktop.
Minimal working Manifest V3 extension.
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
chrome.browserAction.onClicked.addListener(handleBrowserActionClicked)
function handleBrowserActionClicked(tab) {
const opts = {
url: chrome.runtime.getURL('popup.html')
};
chrome.windows.create(opts, handleWindowCreated);
}
function handleWindowCreated(window) {
console.log('done');
}
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{
"name": "Basic MV3 Demo",
"version": "0.1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"browser_action": {
"default_title": "Click me to open a new window"
}
}
<!DOCTYPE html>
<html lang="en">
<!--
Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0
-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h2>Hello, world!</h2>
</body>
</html>
@e-roy
Copy link

e-roy commented Jan 29, 2021

Hi, thank you for this example!

Changes I made to make this work:

background.js
3 chrome.action.onClicked.addListener(handleBrowserActionClicked)

manifest
8 "action": {

Hope this helps the next person :)

@SimGus
Copy link

SimGus commented Mar 30, 2021

Thank both of you for this example, it really helped!

If anybody needs a minimal template of such an extension to start development, I made this repo. It also gives some information the official documentation is currently lacking.

I hope this can help as well!

@firozzer
Copy link

firozzer commented Apr 6, 2021

Hi, thank you for this example!

Changes I made to make this work:

background.js
3 chrome.action.onClicked.addListener(handleBrowserActionClicked)

manifest
8 "action": {

Hope this helps the next person :)

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment