Hi!
The case is as follow.
- Content script creates object and clone it to
window
to be accessible from page script code. - Cloned content script object has a method which is asynchronous call and I want to return Promise to page script.
Xray vision prevent returning object to page script.
The only way I found to inform page script from content script about state of async method is Window.postMessage.
Are there any other solution to implement in more elegant way to using Promise style in calling content script object from page script code?
Here is sample code which is disallowed from Xray vision to return promise .
// content script
var jsPrintSetup = {
print: function(printSettings) {
return new Promise(
function (resolve, reject) {
// calling async print ...
if (some_condition)
resolve(res);
else
reject(err);
}
);
}
}
window.wrappedJSObject.jsPrintSetup = cloneInto(
jsPrintSetup,
window,
{cloneFunctions: true}
);
// page script
window.jsPrintSetup.print(null).then(
(res) => {
// ok resolved
}
, (err) => {
// rejected
}
);