mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 07:53:34 +01:00
feat: chrome extension migrate to manifest v3
This commit is contained in:
parent
d91ee36192
commit
075e9162c2
@ -1,36 +1,35 @@
|
|||||||
(function () {
|
let currentTab = {
|
||||||
let currentTab = {
|
|
||||||
id: null,
|
id: null,
|
||||||
url: null,
|
url: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const getExtensionId = () => {
|
const getExtensionId = () => {
|
||||||
const matches = chrome.runtime.getURL('x').match(/.*\/\/(.*)\/x$/);
|
const matches = chrome.runtime.getURL('x').match(/.*\/\/(.*)\/x$/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
return matches[1];
|
return matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return chrome.runtime.id;
|
return chrome.runtime.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a new tab for the extension
|
// Create a new tab for the extension
|
||||||
function createNewTab() {
|
function createNewTab() {
|
||||||
chrome.tabs.create({ url: 'index.html' }, function (tab) {
|
chrome.tabs.create({ url: 'index.html' }, function (tab) {
|
||||||
currentTab = {
|
currentTab = {
|
||||||
id: tab.id,
|
id: tab.id,
|
||||||
url: tab.url
|
url: tab.url
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focus on the open extension tab
|
// Focus on the open extension tab
|
||||||
function focusTab(tabId) {
|
function focusTab(tabId) {
|
||||||
var updateProperties = { "active": true };
|
var updateProperties = { "active": true };
|
||||||
chrome.tabs.update(tabId, updateProperties, function (tab) { });
|
chrome.tabs.update(tabId, updateProperties, function (tab) { });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the extension tab when the extension icon is clicked
|
// Open the extension tab when the extension icon is clicked
|
||||||
chrome.browserAction.onClicked.addListener(function (tab) {
|
chrome.action.onClicked.addListener(function (tab) {
|
||||||
if (!currentTab || !currentTab.id) {
|
if (!currentTab || !currentTab.id) {
|
||||||
createNewTab();
|
createNewTab();
|
||||||
} else {
|
} else {
|
||||||
@ -43,12 +42,11 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// When a tab is closed, check if it is the extension tab that was closed, and unset currentTabId
|
// When a tab is closed, check if it is the extension tab that was closed, and unset currentTabId
|
||||||
chrome.tabs.onRemoved.addListener(function (tabId) {
|
chrome.tabs.onRemoved.addListener(function (tabId) {
|
||||||
if (tabId === currentTab.id) {
|
if (tabId === currentTab.id) {
|
||||||
currentTab = {};
|
currentTab = {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 3,
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"name": "Bruno API Client",
|
"name": "Bruno API Client",
|
||||||
"short_name": "Bruno",
|
"short_name": "Bruno",
|
||||||
@ -10,17 +10,17 @@
|
|||||||
"128": "assets/images/logo-128x128.png"
|
"128": "assets/images/logo-128x128.png"
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"service_worker": "js/background.js"
|
||||||
"js/background.js"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"browser_action": {
|
"action": {
|
||||||
"default_icon": "assets/images/logo-128x128.png"
|
"default_icon": "assets/images/logo-128x128.png"
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"http://*/",
|
|
||||||
"https://*/",
|
|
||||||
"tabs",
|
"tabs",
|
||||||
"storage"
|
"storage"
|
||||||
|
],
|
||||||
|
"host_permissions": [
|
||||||
|
"http://*/",
|
||||||
|
"https://*/"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -17,7 +17,10 @@ cp -r packages/bruno-chrome-extension/* chrome-extension
|
|||||||
|
|
||||||
# Filenames starting with "_" are reserved for use by the system
|
# Filenames starting with "_" are reserved for use by the system
|
||||||
mv chrome-extension/_next chrome-extension/next
|
mv chrome-extension/_next chrome-extension/next
|
||||||
sed -i 's@/_next/@/next/@g' chrome-extension/**.html
|
sed -i'' -e 's@/_next/@/next/@g' chrome-extension/**.html
|
||||||
|
|
||||||
# Remove sourcemaps
|
# Remove sourcemaps
|
||||||
find chrome-extension -name '*.map' -type f -delete
|
find chrome-extension -name '*.map' -type f -delete
|
||||||
|
|
||||||
|
# Compress the chrome-extension directory into a zip file
|
||||||
|
zip -r bruno.zip chrome-extension
|
Loading…
Reference in New Issue
Block a user