如何从 chrome contentscript 获取页面中富文本编辑器生成的 iframe 中选中的文本

我想在 Chrome 扩展中获取页面中富文本编辑器生成的 iframe 中选中的文本,我尝试了两种方法,但都失败了。

1. 在定义 contentscript 时指定 "all_frame": true

contentscript 无法被注入到动态生成并且没有指定 src 的 iframe 中,所以脚本根本不会在富文本编辑器的 iframe 中执行。

2. 遍历页面中所有的 iframe,找出 document.bodycontenteditable="true" 的那个,然后获取里面的选中文本

因为 origin 和 protocol 不同,导致对该 iframe 没有访问权限。

Blocked a frame with origin "https://www.evernote.com" from accessing a frame with origin "chrome-extension://oknpjjbmpnndlpmnhmekjpocelpnlfdi". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "chrome-extension". Protocols must match.


求教各位,有没有什么好的办法。

阅读 7.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题