使用 Firefox WebDriver,我可以读取扩展程序的本地存储,如下所示:
extension_path = "/path/to/my/extension"
info = {
"extension_id": f"foobar",
"uuid": uuid.uuid4(),
}
base_url = f"moz-extension://{info['uuid']}/"
opts = FirefoxOptions()
opts.set_preference('extensions.webextensions.uuids', '{"%s": "%s"}' % (
info["extension_id"], info["uuid"]))
driver = webdriver.Firefox(options=opts)
driver.install_addon(extension_path, temporary=True)
driver.get(f"{base_url}_generated_background_page.html")
results = self.driver.execute_async_script((
"let done = arguments[arguments.length - 1],"
" store_name = arguments[0];"
"browser.storage.local.get([store_name], function (res) {"
" done(res[store_name]);"
"});"
), "foo")
Run Code Online (Sandbox Code Playgroud)
如何在 macOS 上使用 Safari WebDriver 执行相同操作?我已经使用移植了该扩展xcrun safari-web-extension-converter /path/to/my/extension,并构建并手动测试了它在 Safari 中的工作情况。在 Safari 中,我可以找到Develop -> Web Extension Background Pages -> <my web extension>扩展程序的 …
Safari 现在可以使用网络扩展。
但不支持browser.identityor 。chrome.identity所以launchWebAuthFlow不工作。
在文档中他们只是说。
身份 不支持。在新选项卡中启动 OAuth 流程。
我该怎么做?有例子吗?
我正在尝试为我的本机应用程序创建 Safari Web 扩展。我想要一个带有按钮的弹出窗口,单击该按钮将与我的本机应用程序进行通信。在开始这部分之前,我在发送本机消息并在beginRequest符合NSExtensionRequestHandling协议的类的函数中处理它时遇到了问题。我没有做太多事情,因为我依赖于 Xcode 生成的代码。
manifest.json我添加了这样nativeMessaging的权限:
"permissions": [ "nativeMessaging" ]
Run Code Online (Sandbox Code Playgroud)
popup.js其中包含事件监听器:
console.log("Hello World!", browser);
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('clickIt');
checkPageButton.addEventListener('click', function() {
console.log("click")
browser.runtime.sendNativeMessage({ message: "Hello" });
}, false)
}, false)
Run Code Online (Sandbox Code Playgroud)
当我检查弹出元素时,我可以看到消息Hello World并显示click消息,但正如我之前提到的 -beginRequest没有被调用。有什么遗漏吗?我也观看了WWDC20 的Meet Safari Web Extensions 会议,但没有找到答案。
javascript safari-extension safariservices safari-web-extension