forked from chromedp/chromedp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
function deliverError(name, seq, message, stack) { | ||
const error = new Error(message); | ||
error.stack = stack; | ||
window["CDP_BINDING_" + name].callbacks.get(seq).reject(error); | ||
window["CDP_BINDING_" + name].callbacks.delete(seq); | ||
} | ||
var chromedpExposeFunc = chromedpExposeFunc || { | ||
bindings: {}, | ||
deliverError: function (name, seq, message) { | ||
const error = new Error(message); | ||
chromedpExposeFunc.bindings[name].callbacks.get(seq).reject(error); | ||
chromedpExposeFunc.bindings[name].callbacks.delete(seq); | ||
}, | ||
deliverResult: function (name, seq, result) { | ||
chromedpExposeFunc.bindings[name].callbacks.get(seq).resolve(result); | ||
chromedpExposeFunc.bindings[name].callbacks.delete(seq); | ||
}, | ||
wrapBinding: function (type, name) { | ||
// Store the binding function added by the call of runtime.AddBinding. | ||
chromedpExposeFunc.bindings[name] = window[name]; | ||
|
||
function deliverResult(name, seq, result) { | ||
window["CDP_BINDING_" + name].callbacks.get(seq).resolve(result); | ||
window["CDP_BINDING_" + name].callbacks.delete(seq); | ||
} | ||
// Replace the binding function. | ||
Object.assign(window, { | ||
[name](args) { | ||
if (typeof args != 'string') { | ||
return Promise.reject( | ||
new Error( | ||
'function takes exactly one argument, this argument should be string' | ||
) | ||
); | ||
} | ||
|
||
function addTargetBinding(type, name) { | ||
// This is the CDP binding. | ||
window["CDP_BINDING_" + name] = window[name]; | ||
|
||
// We replace the CDP binding with a chromedp binding. | ||
Object.assign(window, { | ||
[name](args) { | ||
if(typeof args != "string"){ | ||
return Promise.reject(new Error('function takes exactly one argument, this argument should be string')) | ||
} | ||
const binding = chromedpExposeFunc.bindings[name]; | ||
|
||
// This is the chromedp binding. | ||
const callChromedp = window["CDP_BINDING_" + name]; | ||
binding.callbacks ??= new Map(); | ||
|
||
if (callChromedp.callbacks == undefined) { | ||
callChromedp.callbacks = new Map() | ||
} | ||
if (callChromedp.lastSeq == undefined) { | ||
callChromedp.lastSeq = 0 | ||
} | ||
const seq = (binding.lastSeq ?? 0) + 1; | ||
binding.lastSeq = seq; | ||
|
||
const seq = callChromedp.lastSeq + 1 | ||
callChromedp.lastSeq = seq; | ||
|
||
callChromedp(JSON.stringify({ type, name, seq, args })); | ||
// Call the binding function to trigger runtime.EventBindingCalled. | ||
binding(JSON.stringify({ type, name, seq, args })); | ||
|
||
return new Promise((resolve, reject) => { | ||
callChromedp.callbacks.set(seq, { resolve, reject }); | ||
}); | ||
}, | ||
}); | ||
} | ||
return new Promise((resolve, reject) => { | ||
binding.callbacks.set(seq, { resolve, reject }); | ||
}); | ||
}, | ||
}); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.