gpt4 book ai didi

firefox - 查找当前选项卡的 URL。制作 FireFox 浏览器插件

转载 作者:行者123 更新时间:2023-12-03 21:34:34 26 4
gpt4 key购买 nike

我正在制作 Firefox 浏览器插件,需要找到当前标签页的 url

我试过这篇文章Opening a URL in current tab/window from a Firefox Extension但它告诉我“窗口”没有定义。 (我认为是因为我正在制作附加组件而不是扩展。)

这是我尝试做的事情:

var widgets = require('widget');
var tabs = require('tabs');

var widget1 = widgets.Widget({
id: "widget1",
label: "widget1",
contentURL: "http://www.mozilla.org/favicon",
onClick: function() {
console.log(tabs.url);
}
})

我制作了一个小部件,当我单击它时,当前选项卡的 url 应该是“console.log”。

似乎不会发生!不断收到“信息:未定义”,这显然意味着 tabs.url 没有返回任何内容。但这似乎是根据 https://addons.mozilla.org/en-US/developers/docs/sdk/1.5/packages/addon-kit/docs/tabs.html 使用它的方式

有人有想法么?

谢谢,

将要

最佳答案

您快到了:

const { ActionButton } = require("sdk/ui/button/action");
const clipboard = require("sdk/clipboard");
const tabs = require('sdk/tabs');

let button = ActionButton({
id: "my-button-id",
label: "Button Label",
icon: {
"32": "chrome://mozapps/skin/extensions/extensionGeneric.png"
},
onClick: function(state) {
let url = tabs.activeTab.url;
console.log("active tab url:", url);
require("sdk/notifications").notify({
title: "Active Tab's Url is "+url,
text: "Click to copy.",
onClick: function() {
clipboard.set(url);
}
});
}
});

您应该查看 documentation on the tabs module .

注意:我已更新此代码示例以使用自 Firefox 29 以来可用的新 ui 模块 - 原始问题中使用的“小部件”模块当时有效,但已被弃用,然后被删除。

关于firefox - 查找当前选项卡的 URL。制作 FireFox 浏览器插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582607/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com