electronicjs中的webFrame上下文

时间:2019-01-10 20:41:39

标签: electron

是否有一种方法来获取webFrame上下文来注入chrome-api,就像电子对函数 14 lib/renderer/content-script-injector.js行号中的webContents(或渲染过程)所做的一样>在electronicjs版本 3.0.14 中。

以下代码是从电子仓库中提取的。 runInThisContext是'vm'导入,并且似乎在较重的电子过程中运行。

// Run the code with chrome API integrated.
const runContentScript = function(extensionId, url, code) {
  const context = {};
  require('./chrome-api').injectTo(extensionId, false, context);
  const wrapper = `((chrome) => {\n  ${code}\n  })`;
  const compiledWrapper = runInThisContext(wrapper, {
    filename: url,
    lineOffset: 1,
    displayErrors: true
  });
  return compiledWrapper.call(this, context.chrome);
};

0 个答案:

没有答案