webFrame Context in electronjs

Viewed 106

Is there a way to get webFrame context to inject chrome-api, like electron does for webContents (or renderer process) in file lib/renderer/content-script-injector.js line number of the function 14 in electronjs version 3.0.14.

The following code is extract from electron repo. runInThisContext is 'vm' import and seems to run on rederer process of electron.

// 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 Answers
Related