-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
28 lines (24 loc) · 970 Bytes
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// get submit button from popup.html
let submitAccessCodeButton = document.getElementById("submitAccessCodeButton");
// when the button is clicked, send the access code to the content script
submitAccessCodeButton.addEventListener("click", async () => {
let accessCodeField = document.getElementById("accessCodeField")
let accessCodeText = accessCodeField.value
let [tab] = await chrome.tabs.query({
active: true, currentWindow: true
});
// send to content script
let message = {
messageType: "ACCESS_CODE_FROM_POPUP",
accessCodeText: accessCodeText
}
chrome.tabs.sendMessage(tab.id, message, (response) => {
if (chrome.runtime.lastError) {
// TODO: error handling
// console.error("Error communicating from popup to content_script!")
} else {
console.log("Sent message from popup to content_script!")
console.log(response)
}
});
});