【发布时间】:2019-02-25 01:56:44
【问题描述】:
我在玩一些 chrome 扩展,发现了这个例子:http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/
一切正常,但我想创建自己的扩展程序,并且我想在特定站点上查看 page_action 图标,而不是在其网址中包含“g”的站点。 所以我试着简单地改变这个脚本:
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Called when the url of a tab changes.
function checkForValidUrl(tabId, changeInfo, tab) {
// If the letter 'g' is found in the tab's URL...
if (tab.url.indexOf('g') > -1) {
// ... show the page action.
chrome.pageAction.show(tabId);
}
};
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkForValidUrl);
进入这个:
chrome.pageAction.show(tabId);
但是现在不行了... 我不明白。显然我可以使用一种解决方法,但这不是重点......首先,我必须创建一个背景页面来执行此操作吗?我想是的,但我不明白为什么,为什么 .show 方法不能单独工作? 我试图在谷歌文档和东西中搜索,但我找不到任何有用的东西我不是专家,这是我在谷歌扩展上度过的第一个下午,但我怎么知道“chrome.page.show( tabId)" 如果没有写在任何地方,它必须进入背景页面吗?无意批评,但你们到底是怎么发现的?所有 chrome 方法都必须进入后台页面? 好吧,肯定比它的合法性要多得多。希望你能给我至少一个答案!
【问题讨论】:
-
你给它一个有效的
tabId吗?
标签: javascript google-chrome-extension