Reputation: 1638
The Electron WebView supports a executeJavascript()
method which supposedly executes the provided snippet within the render process of the guest content. However, the example provided below fails with the generic error message Error invoking remote method 'GUEST_VIEW_MANAGER_CALL': Error: An object could not be cloned.
and for the life of me, can't work out what I'm doing wrong.
export default class BrowserView extends ItemView {
private webview: WebviewTag;
private async convertWebpageToNote() {
const pageSource = await this.webview.executeJavaScript((() => ({ // extract the page's source and title
title: window.document.title,
source: window.document.querySelector(":root")?.outerHTML
})).toString())
.then(function ({ title, source }) {
// Convert the collected content back to a `Document` object to pass to `readability`
const doc = window.document.implementation.createHTMLDocument(title);
doc.querySelector(":root")?.replaceWith(source);
return doc;
});
// Snip: Use the `readability` Javascript library to extract the page's useful contents.
}
}
The object supposedly cannot be cloned. Thus, I have tried manually serialising it using JSON as well as returning a plain string and number. None of which yield a successful result.
I'm hoping mostly for insight into why this is failing and possibly a workaround.
For context: I'm writing an Obsidian plugin which embeds a browser into the app for easy note taking on the web and am trying to avoid any complex IPC calls.
The suggested questions box on SE suggests posts which don't have any answers or correctly indicate the inability to pass certain types of objects to the caller, however none of these cases apply here as I cannot send an object which should be serialisable.
Upvotes: 0
Views: 74