Handle executeJavaScript in JavaScript
This commit is contained in:
parent
5b7d1a9890
commit
55dfddba77
8 changed files with 28 additions and 52 deletions
|
@ -57,6 +57,7 @@ PDFPageSize = {
|
|||
|
||||
// Following methods are mapped to webFrame.
|
||||
const webFrameMethods = [
|
||||
'executeJavaScript',
|
||||
'insertText',
|
||||
];
|
||||
|
||||
|
@ -73,21 +74,6 @@ wrapWebContents = function(webContents) {
|
|||
return this._send(channel, slice.call(args));
|
||||
};
|
||||
|
||||
/*
|
||||
Make sure webContents.executeJavaScript would run the code only when the
|
||||
web contents has been loaded.
|
||||
*/
|
||||
webContents.executeJavaScript = function(code, hasUserGesture) {
|
||||
if (hasUserGesture == null) {
|
||||
hasUserGesture = false;
|
||||
}
|
||||
if (this.getURL() && !this.isLoading()) {
|
||||
return this._executeJavaScript(code, hasUserGesture);
|
||||
} else {
|
||||
return webContents.once('did-finish-load', this._executeJavaScript.bind(this, code, hasUserGesture));
|
||||
}
|
||||
};
|
||||
|
||||
/* The navigation controller. */
|
||||
controller = new NavigationController(webContents);
|
||||
ref1 = NavigationController.prototype;
|
||||
|
@ -110,6 +96,20 @@ wrapWebContents = function(webContents) {
|
|||
};
|
||||
}
|
||||
|
||||
// Make sure webContents.executeJavaScript would run the code only when the
|
||||
// webContents has been loaded.
|
||||
const executeJavaScript = webContents.executeJavaScript;
|
||||
webContents.executeJavaScript = function(code, hasUserGesture) {
|
||||
// TODO(zcbenz): Use default parameter after Chrome 49.
|
||||
if (hasUserGesture === undefined)
|
||||
hasUserGesture = false;
|
||||
|
||||
if (this.getURL() && !this.isLoading())
|
||||
return executeJavaScript.call(this, code, hasUserGesture);
|
||||
else
|
||||
return this.once('did-finish-load', executeJavaScript.bind(this, code, hasUserGesture));
|
||||
};
|
||||
|
||||
/* Dispatch IPC messages to the ipc module. */
|
||||
webContents.on('ipc-message', function(event, packed) {
|
||||
var args, channel;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue