index.js
/**
   * Run arbitrary javascript code inside webview context.
   * @param {string} code Javascript code.
   * @returns {Promise} Promise object represents the result of the script.
   */
Run arbitrary javascript code inside webview context.
@param {string} code Javascript code.
@returns {Promise} Promise object represents the result of the script.
Run arbitrary javascript code inside webview context . @param { string } code Javascript code . @returns { Promise } Promise object represents the result of the script .
runJs(code) {
    return new Promise((resolve, reject) => {
      this.webview.executeScript({
        code: `
          ;(function() {
            ${code}
          })();
        `,
      }, (results) => {
        if (chrome && chrome.runtime && chrome.runtime.lastError) {
          return reject(new Error(`Chrome last error: ${chrome.runtime.lastError.message || 'undefined'}`));
        }
        return resolve(results && results[0]);
      });
    });
  }
runJs ( code ) { return new Promise ( ( resolve , reject ) => { this . webview . executeScript ( { code : ` ${ code } ` , } , ( results ) => { if ( chrome && chrome . runtime && chrome . runtime . lastError ) { return reject ( new Error ( ` ${ chrome . runtime . lastError . message || 'undefined' } ` ) ) ; } return resolve ( results && results [ 0 ] ) ; } ) ; } ) ; }
Run arbitrary javascript code inside webview context.
Run arbitrary javascript code inside webview context .