|
@@ -6,6 +6,8 @@ const path = require('path')
|
|
|
const url = require('url')
|
|
|
const {app, ipcMain, session, NavigationController, deprecate} = electron
|
|
|
|
|
|
+const errorUtils = require('../../common/error-utils')
|
|
|
+
|
|
|
// session is not used here, the purpose is to make sure session is initalized
|
|
|
// before the webContents module.
|
|
|
// eslint-disable-next-line
|
|
@@ -111,17 +113,6 @@ const webFrameMethods = [
|
|
|
'setLayoutZoomLevelLimits',
|
|
|
'setVisualZoomLevelLimits'
|
|
|
]
|
|
|
-const webFrameMethodsWithResult = []
|
|
|
-
|
|
|
-const errorConstructors = {
|
|
|
- Error,
|
|
|
- EvalError,
|
|
|
- RangeError,
|
|
|
- ReferenceError,
|
|
|
- SyntaxError,
|
|
|
- TypeError,
|
|
|
- URIError
|
|
|
-}
|
|
|
|
|
|
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
|
|
return new Promise((resolve, reject) => {
|
|
@@ -131,40 +122,18 @@ const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
|
|
if (typeof callback === 'function') callback(result)
|
|
|
resolve(result)
|
|
|
} else {
|
|
|
- if (error.__ELECTRON_SERIALIZED_ERROR__ && errorConstructors[error.name]) {
|
|
|
- const rehydratedError = new errorConstructors[error.name](error.message)
|
|
|
- rehydratedError.stack = error.stack
|
|
|
-
|
|
|
- reject(rehydratedError)
|
|
|
- } else {
|
|
|
- reject(error)
|
|
|
- }
|
|
|
+ reject(errorUtils.deserialize(error))
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-const syncWebFrameMethods = function (requestId, method, callback, ...args) {
|
|
|
- this.send('ELECTRON_INTERNAL_RENDERER_SYNC_WEB_FRAME_METHOD', requestId, method, args)
|
|
|
- ipcMain.once(`ELECTRON_INTERNAL_BROWSER_SYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
|
|
- if (callback) callback(result)
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
for (const method of webFrameMethods) {
|
|
|
WebContents.prototype[method] = function (...args) {
|
|
|
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-for (const method of webFrameMethodsWithResult) {
|
|
|
- WebContents.prototype[method] = function (...args) {
|
|
|
- const callback = args[args.length - 1]
|
|
|
- const actualArgs = args.slice(0, args.length - 2)
|
|
|
- syncWebFrameMethods.call(this, getNextId(), method, callback, ...actualArgs)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// Make sure WebContents::executeJavaScript would run the code only when the
|
|
|
// WebContents has been loaded.
|
|
|
WebContents.prototype.executeJavaScript = function (code, hasUserGesture, callback) {
|