zoukankan      html  css  js  c++  java
  • Chrome Extension 记录

    传递选定元素到内容脚本

    内容脚本不能直接访问当前选中的元素。但是,任何使用 inspectedWindow.eval 来执行的代码都可以在 DevTools 控制台和命令行的 API 中使用。例如,在测试代码时,你可以使用 $0 访问当前被选定的元素。

    要传递选中的元素到内容脚本,可以如下完成:

    • 在内容脚本中,创建一个函数,将选定参数作为这个函数的参数。
    • 在 DevTools 页面中使用在useContentScriptContext:true的选项中的inspectedWindow.eval来该函数方法。

    在内容脚本中你的函数代码可能是这个样子:

    function setSelectedElement(el) {
        // do something with the selected element
    }
    

    在 DevTools 页面调用这个方法,像这样:

    chrome.devtools.inspectedWindow.eval("setSelectedElement($0)",
        { useContentScriptContext: true });
    

    useContentScriptContext:true 选项限定的是表达必须在相同的上下文中的内容脚本中进行计算,所以它可以使用setSelectedElement方法。

    来源:https://www.breakyizhan.com/chromeconsole/2281.html?amp

    chrome.devtools.panels.openResource('https://www.sogou.com/web/css/yuyin.v1.0.1.css', 45, res => {
    console.log(20, 'openResource', res);
    });

    chrome.desktopCapture.chooseDesktopMedia

  • 相关阅读:
    手机操作
    模拟手机操作
    get_attribute_value
    test_order
    信息收集-FOFA资产收集与FOFA api
    html中form讲解
    安装redis
    yum vs rpm
    yum 安装java环境
    显示当前目录所有文件大小的命令ls -lht
  • 原文地址:https://www.cnblogs.com/linr/p/11929450.html
Copyright © 2011-2022 走看看