Skip to content

Instantly share code, notes, and snippets.

@akirattii
Last active June 4, 2021 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akirattii/b2070e184035aef98db832bedf7f747e to your computer and use it in GitHub Desktop.
Save akirattii/b2070e184035aef98db832bedf7f747e to your computer and use it in GitHub Desktop.
an example of chrome extension, which can be opened as new tab by click its browser icon.
console.log("background");
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({
'url': chrome.extension.getURL('popup.html')
}, function(tab) {
// Tab opened.
});
});
console.log("content script");
{
"name": "example-app",
"version": "0.1.0",
"manifest_version": 2,
"description": "a example extension for Chrome",
"author": "Taro TANAKA <tanaka@example.com> (http://www.example.com)",
"permissions": [
"<all_urls>",
"storage",
"unlimitedStorage",
"tabs",
"activeTab",
"http://*/*",
"https://*/*"
],
"icons": {
"128": "./icon.png"
},
"web_accessible_resources": [
"./icon.png"
],
"content_scripts": [{
"all_frames": true,
"matches": ["<all_urls>"],
"js": ["./content.js"],
"css": []
}],
"background": {
"scripts": ["./background.js"],
"persistent": false
},
"browser_action": {
"default_icon": "./icon.png"
},
"update_url": "https://clients2.google.com/service/update2/crx"
}
<html>
<head>
<meta charset="utf-8">
<title>example-app</title>
<script src="extlib/js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="extlib/css/bootstrap.min.css">
<script src="extlib/js/bootstrap.min.js"></script>
</head>
<body class="container mx-auto pb-4">
<div>Hello chrome extension!<div>
<script src="popup.js"></script>
</body>
</html>
console.log("popup script");
if ($) {
console.log("jquery available!");
}
// here can use jQuery...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment