. */ function getCurrentTabUrl(callback) { // Query filter to be passed to chrome.tabs.query - see...tabs#method-query var queryInfo = { active: true, currentWindow: true }; chrome.tabs.query...(queryInfo, (tabs) => { // chrome.tabs.query invokes the callback with a list of tabs that match...This means that // you CANNOT do something like this: // // var url; // chrome.tabs.query...(tabs) => { // url = tabs[0].url; // }); // alert(url); // Shows "undefined", because chrome.tabs.query
; switch(LocalDB.Content){ case 'TEST': chrome.tabs.query...default: break; } }else{ chrome.tabs.query...DBdata('get',function(res){ var LocalDB=res.LocalDB; console.log(LocalDB) chrome.tabs.query
主要利用chrome.tabs.query与chrome.tabs.sendMessage这两个api实现 // set.js function sendMessageToActiveTab(...message) { // 获取当前活动标签 chrome.tabs.query({}, function (tabs) { tabs .filter((v)...其实我们只需要修改一行代码即可 function sendMessageToActiveTab(message) { // 向所有的tabde chrome.tabs.query({...content的通信,借助chrome.runtime.sendMessage实现 在插件的内部页面如何与其他页面通信,比如一个插件的设置页与content.js实时通信,我们是借助先查询所有的tabs,chrome.tabs.query
cookieList = document.getElementById('cookie-list'); getButton.addEventListener('click', function() { chrome.tabs.query...cookieList = document.getElementById('cookie-list'); getButton.addEventListener('click', function() { chrome.tabs.query...toast.style.display = 'none'; }, 2000); } getButton.addEventListener('click', function() { chrome.tabs.query
port.postMessage({ res }); }); } }); } }); 3.添加popup向contentScript发送消息的实例 popup.js chrome.tabs.query
setPageBackgroundColor into current page startDel.addEventListener("click", async () => { let [tab] = await chrome.tabs.query
console.log('received user data', response); }); popup.js向content.js通信 在popup页面需要查找当前激活的tabs // popup.js chrome.tabs.query...heightValue } chrome.action.setBadgeText({ text: inputColorValue }); // 扩展脚本向content发出信息 chrome.tabs.query
// chrome.tabs 读取浏览器已打开的tab页签,其中'active': true访问到的是当前所处的标签页 // WINDOW_ID_CURRENT 当前标签页id chrome.tabs.query
return { url: '' }; } let queryOptions = { active: true, currentWindow: true }; let [tab] = await chrome.tabs.query
popup.js $("input:radio[name='options']").change(function () { chrome.tabs.query({active: true
,如果为all,则收集所有图片,为attr则只收集属性图 * @param attr {string} 用;分隔开的属性规则 */ sendMessage(action, attr) { chrome.tabs.query
url: "http://localhost:3000/", name: "xToken" }, async (res) => { const [tab] = await chrome.tabs.query
此示例适用于 Service Worker、弹出式窗口和作为标签页打开的 chrome-extension:// 页面 (async () => { const [tab] = await chrome.tabs.query...}) tabs创建页签 首先在manifest.json的权限中添加tabs配置 { "permissions": ["tabs"] } 添加tabs的相关操作 chrome.tabs.query...({}, function(tabs){ console.log(tabs) }) function getCurrentTab(){ let [tab] = chrome.tabs.query
obj); chrome.storage.sync.set(obj, function() { //console.log('send callback'); chrome.tabs.query...: ' + sendRequest); chrome.storage.sync.remove(sender.url, function() { chrome.tabs.query
function getCurrentTabId(callback) { chrome.tabs.query({ active: true, currentWindow: true }, function
videoType); }); }) } popup.js function sendMessageToContentScript(message, callback) { chrome.tabs.query
3.2 popup或者background页和content_script通信 这里我们使用chrome的tabs API,如下:// popup.js // 发送消息给content_script chrome.tabs.query...content').append(imgWrap); $('.empty').hide(); }) }); $('#activeBtn').click(function(element) { chrome.tabs.query
领取专属 10元无门槛券
手把手带您无忧上云