New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render raw HTML instead of navigating to a URL #95
Comments
Maybe using const CDP = require('chrome-remote-interface');
CDP(async (client) => {
const {Page} = client;
try {
const {frameId} = await Page.navigate({url: 'about:blank'});
const html = '<marquee>It works!</marquee>';
await Page.setDocumentContent({frameId, html});
} catch (err) {
console.error(err);
client.close();
}
}).on('error', (err) => {
console.error(err);
}); Note that you can fetch |
@cyrus-and This works for html and css but remote scripts does not get loaded. Any ideas how to invoke them? |
@utkuturunc you're right it doesn't work for scripts, you should submit an issue here. You can always evaluate arbitrary JavaScript code in the tab context using, for example, the |
@cyrus-and Thanks for the replies. I will submit that issue. In the mean time, if anybody wants to do this you can simply convert the html string to a data uri and navigate to that uri. This also makes getting the frameId easier. |
@utkuturunc did you get the issue submitted? |
Sorry for the delay. I just did. By the way I cannot capture the frameId using any event, Page.frameAttached does not seem to be firing. I couldn't get it to work without navigating to a blank page. |
@utkuturunc AFAIK Alternatively you can use const CDP = require('chrome-remote-interface');
CDP(async (client) => {
try {
const {Page} = client;
const {frameTree} = await Page.getResourceTree();
const root = frameTree.frame;
console.log(root.id);
} catch (err) {
console.error(err);
} finally {
client.close();
}
}).on('error', (err) => {
console.error(err);
}); |
Is there a way to have Chrome render a string of raw HTML instead of having it navigate to a URL?
The text was updated successfully, but these errors were encountered: