Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@e-roy 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

This comment has been minimized.

Copy link

@SimGus 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!

@XtremePwnership

This comment has been minimized.

Copy link

@XtremePwnership XtremePwnership 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