网页中的chrome.storage.sync.get [英] chrome.storage.sync.get from web page

查看:210
本文介绍了网页中的chrome.storage.sync.get的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我希望能够从我的扩展插入的网页中的内联脚本访问存储在chrome.storage.sync中的信息。 尝试使用chrome.storage.sync时,不能从未定义调用同步。以同样的方式,我无法调用chrome.runtime.sendMessage。 此答案教会了我无法从注入脚本访问Chrome API。



我发现使用这种技术最终可以调用sendMessage: https: //developer.chrome.com/extensions/messaging#external-webpage ,然后我可以在回调中返回想要的数据。



但是我想知道,有没有更好的方法来做到这一点?从注入的脚本访问chrome.storage数据?事实上,我需要使用我的扩展作为参数真的不是很好... ...

谢谢!

解决方案

由于您的注入脚本与安全角度的页面本身的代码基本相同,因此无法简化此任务。

externally_connectable 是您找到的方法之一。 另一种方式是说话与内容脚本本身。您可以使用自定义事件或 window.postMessage


Hello guys,

I want to be able to access informations stored in chrome.storage.sync from an inline script within a web page, injected by my extension.

When trying to use chrome.storage.sync, sync can't be called from "undefined". In the same way, I couldn't call chrome.runtime.sendMessage. This answer taught me I can't access Chrome APIs from an injected script.

I found out that I could eventually call sendMessage using this technique : https://developer.chrome.com/extensions/messaging#external-webpage and then I could return the wanted data in the callback.

But I wanted to know, is there a better way to do this ? Accessing chrome.storage data from the injected script ? The fact that I need to use my extension's as an argument is really not great...

Thanks !

解决方案

Since your injected script is essentially the same as the page's own code from a security perspective, there's no way to make this task easy.

externally_connectable that you found is one of the ways to do it.

The other way is to talk with the content script itself. You can do so with custom events or window.postMessage.

这篇关于网页中的chrome.storage.sync.get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆