谁能告诉如何复制整个页面,类似于按 Ctrl+A,然后将当前选项卡复制到剪贴板。
目前我有这个,但尽管扩展已成功添加到 chrome,但它什么也没做:
清单文件
"permissions":
[
   "clipboardRead",
   "clipboardWrite"
],
// etc
内容脚本
chrome.extension.sendRequest({ text: "text you want to copy" });
背景页面
<html>
 <head>
 <script type="text/javascript">
   chrome.extension.onRequest.addListener(function (msg, sender, sendResponse) {
      var textarea = document.getElementById("tmp-clipboard");
      // now we put the message in the textarea
      textarea.value = msg.text;
      // and copy the text from the textarea
      textarea.select();
      document.execCommand("copy", false, null);
      // finally, cleanup / close the connection
      sendResponse({});
    });
  </script>
  </head>
  <body>
    <textarea id="tmp-clipboard"></textarea>
  </body>
</html>
弹出
<textarea id="tmp-clipboard"></textarea>
<input type="button" id="btn" value="Copy Page">
我无法让它工作,想知道我在这里缺少什么。
任何人都可以指导如何在当前选项卡中模仿Ctrl+A后跟Ctrl+C以便它存储在剪贴板中吗?