browser-plugin-creator
Version:
A modern scaffolding tool for creating browser extensions with ease
25 lines (23 loc) • 692 B
JavaScript
// 后台服务工作线程
chrome.runtime.onInstalled.addListener(() => {
console.log('{{name}} DevTools扩展已安装');
});
// 监听来自内容脚本的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === 'GET_TAB_INFO') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
sendResponse({
tabId: tabs[0].id,
url: tabs[0].url,
title: tabs[0].title
});
});
return true;
}
});
// 监听标签页更新
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete') {
console.log(`页面加载完成: ${tab.url}`);
}
});