Skip to content

Commit

Permalink
Convert to manifest v3 (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner authored Sep 5, 2023
1 parent 7de2c2a commit 1bb4aa5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Long lived background script running in the browser, works in tandem with the
* client-script to coordinate messaging between EmberDebug, EmberInspector and the
* ClientApp. The background-script serves as a proxy between the EmberInspector
* ClientApp. The background.js script serves as a proxy between the EmberInspector
* and the content-script.
*
* It is also responsible for showing the Ember icon and tooltip in the url bar.
Expand Down Expand Up @@ -32,26 +32,26 @@
}

/**
* Creates the title for the pageAction for the current ClientApp
* Creates the title for the action for the current ClientApp
* @param {Number} tabId - the current tab
*/
function setActionTitle(tabId) {
chrome.pageAction.setTitle({
chrome.action.setTitle({
tabId: tabId,
title: generateVersionsTooltip(activeTabs[tabId])
});
}

/**
* Update the tab's pageAction: https://developer.chrome.com/extensions/pageAction
* Update the tab's action: https://developer.chrome.com/extensions/pageAction
* If the user has choosen to display it, the icon is shown and the title
* is updated to display the ClientApp's information in the tooltip.
* @param {Number} tabId - the current tab
*/
function updateTabAction(tabId) {
chrome.storage.sync.get("options", function(data) {
if (!data.options || !data.options.showTomster) { return; }
chrome.pageAction.show(tabId);
chrome.action.show(tabId);
setActionTitle(tabId);
});
}
Expand All @@ -66,7 +66,7 @@
return;
}

chrome.pageAction.hide(tabId);
chrome.action.hide(tabId);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions skeletons/web-extension/content-script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* global chrome*/

/**
* Content script injected into the app page by chrome, works in tandem with the
* background-script to coordinate messaging between EmberDebug, EmberInspector and the
* Content script injected into the app page by chrome, works in tandem with
* background.js to coordinate messaging between EmberDebug, EmberInspector and the
* ClientApp. The content-script serves as a proxy between EmberDebug
* and the background-script.
* and background.js.
*
* Content scripts are loaded into every page, and have access to the DOM. This uses that
* to inject the in-page-script to determine the ClientApp version onLoad.
Expand All @@ -18,7 +18,7 @@
* that proxies between the content-script and EmberDebug using a MessagingChannel.
*
* All events from the window are filtered by checking that data and data.type
* properties exist before sending messages on to the background-script.
* properties exist before sending messages on to the background script.
*
* See:
* https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API
Expand All @@ -38,7 +38,7 @@
* @param {Object} emberDebugPort
*/
function listenToEmberDebugPort(emberDebugPort) {
// listen for messages from EmberDebug, and pass them on to the background-script
// listen for messages from EmberDebug, and pass them on to the background script
emberDebugPort.addEventListener('message', function(event) {
chrome.runtime.sendMessage(event.data);
});
Expand Down
55 changes: 29 additions & 26 deletions skeletons/web-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
{
"manifest_version": 2,
"manifest_version": 3,

"name": "Ember Inspector",
"description": "Tool for debugging Ember applications.",
"version": "{{EMBER_INSPECTOR_VERSION}}",

"icons": {
"16": "{{PANE_ROOT}}/assets/images/icon16.png",
"16": "{{PANE_ROOT}}/assets/images/icon16.png",
"32": "{{PANE_ROOT}}/assets/images/icon38.png",
"48": "{{PANE_ROOT}}/assets/images/icon48.png",
"48": "{{PANE_ROOT}}/assets/images/icon48.png",
"128": "{{PANE_ROOT}}/assets/images/icon128.png"
},

"permissions": [
"<all_urls>",
"storage",
"contextMenus"
],

"content_security_policy": "script-src 'self'; object-src 'self'",
"devtools_page": "devtools.html",
"permissions": ["<all_urls>", "storage", "contextMenus"],

"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["boot.js"],
"run_at": "document_start",
"match_about_blank": true,
"all_frames": true
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
},

"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["boot.js"],
"run_at": "document_start",
"match_about_blank": true,
"all_frames": true
},
{
"matches": ["<all_urls>"],
"js": ["content-script.js"],
"run_at": "document_end",
"match_about_blank": true,
"all_frames": true
}],
}
],

"background": {
"scripts": ["background-script.js"]
},
"devtools_page": "devtools.html",

"page_action": {
"action": {
"default_icon": {
"19": "{{PANE_ROOT}}/assets/images/icon19.png",
"38": "{{PANE_ROOT}}/assets/images/icon38.png"
},
"default_title": "This webpage is not running Ember.js"
},

"web_accessible_resources": [
"scripts/in-page-script.js"
],
"background": {
"service_worker": "background.js"
},

"options_ui": {
"page": "options-dialog.html"
}
},

"web_accessible_resources": [
{
"resources": ["scripts/in-page-script.js"]
}
]
}
4 changes: 1 addition & 3 deletions tests/integration/injection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ module('Integration | Injection', function (hooks) {

async function inject(owner, assert) {
if (injected) return;
const backgroundScript = await (
await fetch('/background-script.js')
).text();
const backgroundScript = await (await fetch('/background.js')).text();
{
// eslint-disable-next-line no-unused-vars
const chrome = backgroundChromeApi;
Expand Down

0 comments on commit 1bb4aa5

Please sign in to comment.