首页 > 解决方案 > 我在使 istrusted 事件为 true 以单击网页时遇到问题。我正在使用 chrome 扩展程序单击

问题描述

我面临着使点击事件在 chrome 扩展中受信任的问题。我已经看到了一个堆栈溢出答案,它描述了我们可以在 chrome.debugger.attach 的帮助下完成,但是我不确定如何将它包含到我的代码中。抱歉,我对扩展很陌生,我已经编写了 js 代码来单击按钮,但是它发送istrusted=false.

我有一个清单文件,一个alert.js文件和一个code.js包含单击按钮的代码的文件。

这是我在 StackOverflow 上看到的代码,但我无法实现它:

chrome.debugger.attach(target, "1.2", function()
  {
  chrome.debugger.sendCommand(target, "Input.dispatchMouseEvent", arguments)
})

我的 alert.js 文件

injectScript( chrome.extension.getURL('code.js'), 'body');
function injectScript(file, node) 
  {
  var th = document.getElementsByTagName(node)[0];
  var s = document.createElement('script');
  s.setAttribute('type', 'text/javascript');
  s.setAttribute('src', file);
  th.appendChild(s);
}

我的 code.js 文件是一个小代码,用于单击我需要发送可信事件的按钮。

我只需要发送istrusted到 true ,因为许多网站可以跟踪用户正在使用它点击脚本。

标签: javascriptgoogle-chrome-extension

解决方案


推荐阅读