當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript webFrame.executeJavaScript方法代碼示例

本文整理匯總了TypeScript中electron.webFrame.executeJavaScript方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript webFrame.executeJavaScript方法的具體用法?TypeScript webFrame.executeJavaScript怎麽用?TypeScript webFrame.executeJavaScript使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在electron.webFrame的用法示例。


在下文中一共展示了webFrame.executeJavaScript方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

const isUnsafeEvalEnabled = function () {
  return webFrame.executeJavaScript(`(${(() => {
    try {
      new Function('') // eslint-disable-line no-new,no-new-func
    } catch {
      return false
    }
    return true
  }).toString()})()`, false)
}
開發者ID:doridoridoriand,項目名稱:electron,代碼行數:10,代碼來源:security-warnings.ts

示例2: Promise

 return new Promise((resolve) => {
   webFrame.executeJavaScript(`(${(() => {
     try {
       new Function('') // eslint-disable-line no-new,no-new-func
     } catch {
       return false
     }
     return true
   }).toString()})()`, false, resolve)
 })
開發者ID:vwvww,項目名稱:electron,代碼行數:10,代碼來源:security-warnings.ts

示例3:

		return !(require('spellchecker').isMisspelled(text));
	}
});

webFrame.registerURLSchemeAsSecure('app');
webFrame.registerURLSchemeAsBypassingCSP('app');
webFrame.registerURLSchemeAsPrivileged('app');
webFrame.registerURLSchemeAsPrivileged('app', {
	secure: true,
	supportFetchAPI: true,
});

webFrame.insertText('text');

webFrame.executeJavaScript('JSON.stringify({})', false, (result) => {
    console.log(result);
}).then((result: string) => console.log('OK:' + result));

console.log(webFrame.getResourceUsage());
webFrame.clearCache();

// clipboard
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md

clipboard.writeText('Example String');
clipboard.writeText('Example String', 'selection');
console.log(clipboard.readText('selection'));
console.log(clipboard.availableFormats());
clipboard.clear();

clipboard.write({
開發者ID:longlho,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:github-electron-renderer-tests.ts

示例4:

webFrame.setZoomLevelLimits(50, 200);

webFrame.setSpellCheckProvider('en-US', true, {
	spellCheck: text => {
		return !(require('spellchecker').isMisspelled(text));
	}
});

webFrame.registerURLSchemeAsSecure('app');
webFrame.registerURLSchemeAsBypassingCSP('app');
webFrame.registerURLSchemeAsPrivileged('app');

webFrame.insertText('text');

webFrame.executeJavaScript('JSON.stringify({})', false, (result) => {
    console.log(result);
});

console.log(webFrame.getResourceUsage());
webFrame.clearCache();

// clipboard
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md

clipboard.writeText('Example String');
clipboard.writeText('Example String', 'selection');
console.log(clipboard.readText('selection'));
console.log(clipboard.availableFormats());
clipboard.clear();

clipboard.write({
開發者ID:CNManning,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:github-electron-renderer-tests.ts

示例5:

 (async () => {
   // `window.opener` is not available when sandbox is activated,
   // therefore we need to fake the function on backend area and
   // redirect the response to a custom protocol
   await webFrame.executeJavaScript(SingleSignOn.javascriptHelper());
 })();
開發者ID:wireapp,項目名稱:wire-desktop,代碼行數:6,代碼來源:preload-sso.ts

示例6: spellCheck

webFrame.setVisualZoomLevelLimits(50, 200)
webFrame.setLayoutZoomLevelLimits(50, 200)

webFrame.setSpellCheckProvider('en-US', {
  spellCheck (words, callback) {
    setTimeout(() => {
      const spellchecker = require('spellchecker')
      const misspelled = words.filter(x => spellchecker.isMisspelled(x))
      callback(misspelled)
    }, 0)
  }
})

webFrame.insertText('text')

webFrame.executeJavaScript('return true;').then((v: boolean) => console.log(v))
webFrame.executeJavaScript('return true;', true).then((v: boolean) => console.log(v))
webFrame.executeJavaScript('return true;', true)
webFrame.executeJavaScript('return true;', true, (result: boolean) => console.log(result))

console.log(webFrame.getResourceUsage())
webFrame.clearCache()

// clipboard
// https://github.com/atom/electron/blob/master/docs/api/clipboard.md

clipboard.writeText('Example String')
clipboard.writeText('Example String', 'selection')
console.log(clipboard.readText('selection'))
console.log(clipboard.availableFormats())
clipboard.clear()
開發者ID:doridoridoriand,項目名稱:electron,代碼行數:31,代碼來源:renderer.ts


注:本文中的electron.webFrame.executeJavaScript方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。