Implement the reload button in chrome

This commit is contained in:
Lawrence Hook
2020-09-20 18:53:49 -04:00
parent 44b8a00028
commit 8b57695879
3 changed files with 25 additions and 17 deletions
+15 -2
View File
@@ -1,8 +1,21 @@
// Handles message receives
chrome.extension.onMessage.addListener((request, sender, sendResponse) => {
// Options with "page action"
// https://stackoverflow.com/questions/35882089/popup-is-not-appearing-when-used-page-action
const activatePageAction = (request, sender, sendResponse) => {
if (request.message === "activate_icon") {
chrome.pageAction.show(sender.tab.id);
}
// Reload button
if (request.message === "reload_page") {
const activeTab = { active: true, currentWindow: true };
chrome.tabs.query(activeTab, tabs => {
tabs.forEach(tab => {
chrome.tabs.update(tab.id, { url: tab.url });
});
});
}
chrome.extension.onMessage.addListener(activatePageAction);
});
+1 -1
View File
@@ -40,5 +40,5 @@
}
},
"permissions": ["storage"]
"permissions": ["storage", "tabs"]
}
+4 -9
View File
@@ -1,10 +1,5 @@
const reloadButton = document.getElementById("reload_button");
reloadButton.addEventListener("click", reload);
console.log("hi");
async function reload() {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
console.log(tabs);
});
const sendReloadMessage = () => {
chrome.runtime.sendMessage({ "message": "reload_page" });
}
const reloadButton = document.getElementById("reload_button");
reloadButton.addEventListener("click", sendReloadMessage);