
Hi @火火HN,
Your addEventListener
may have been added to an "undefined" element even though you have used getElementById
before. Usually, you'll have to add an onload
event to make sure the button is actually found. You can modify your popup.js
into this one:
window.addEventListener("load", (event) => {
document.getElementById('fillSearch').addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const addressBarInput = tabs[0].url;
const encodedInput = encodeURIComponent(addressBarInput);
const googleSearchURL = 'https://www.google.com/search?q=' + encodedInput;
chrome.tabs.create({url: googleSearchURL});
});
});
});
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Shijie Li