-
Notifications
You must be signed in to change notification settings - Fork 9k
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
The page.setContent() function does not render html source. #2913
Comments
I cannot reproduce with 1.5.0-post on Windows 7 x64 using this code: 'use strict';
const puppeteer = require('puppeteer');
const htmlContent = `
<!doctype html>
<html>
<head><meta charset='UTF-8'><title>Test</title></head>
<body>Test</body>
</html>
`;
puppeteer.launch({ headless: false }).then(async (browser) => {
const page = await browser.newPage();
await page.setContent(htmlContent);
setTimeout(async () => {
console.log(await page.content());
}, 3000);
}); Output and browser screenshot: |
BTW, when I open the result of the |
The difference may be from the |
@aslushnikov Is there a way to provide a base URL for |
The only thing I can think of is injecting |
@aslushnikov Unfortunately, this approach is unavailable due to CSP ( 'use strict';
const fs = require('fs');
const puppeteer = require('puppeteer');
const baseURL = 'https://www.pikicast.com/';
const htmlContent = fs.readFileSync('./src.html', {encoding:'utf-8'})
.replace(/<head>/i, `<head><base href='${baseURL}'>`);
puppeteer.launch({headless:false, dumpio:true}).then(async browser=> {
const page = await browser.newPage();
await page.setBypassCSP(true);
console.log("---------Before rendering---------");
console.log(htmlContent);
await page.setContent(htmlContent);
setTimeout(async () => {
console.log("---------After rendering---------");
console.log(await page.content());
}, 3000);
}); Errors in the browser console:
|
Don't know how we can help here - closing. |
@vsemozhetbyt did you fixed it? I have the same problem. |
@semoal No, I did not, sorry. |
Fixed it with args: Give it a try!! |
I'm going to use the puppeteer to replace phantomjs.
The functions that were used in the past are as follows.
on the command line
load_test_phantomjs.js that used on phantomjs
What is the expected result?
When I used the 'load_test_phantomjs.js' code on phantomjs above, I got rendered results.
I want to get a rendered html using the below puppeteer code.
load_test_puppeteer.js that used on puppeteer
What happens instead?
I got a non-rendered html.
The text was updated successfully, but these errors were encountered: