parent
6fcf3d9148
commit
598f439a32
@ -30,6 +30,7 @@
|
||||
+ [page.addScriptTag(url)](#pageaddscripttagurl)
|
||||
+ [page.click(selector[, options])](#pageclickselector-options)
|
||||
+ [page.close()](#pageclose)
|
||||
+ [page.content()](#pagecontent)
|
||||
+ [page.emulate(options)](#pageemulateoptions)
|
||||
+ [page.emulateMedia(mediaType)](#pageemulatemediamediatype)
|
||||
+ [page.evaluate(pageFunction, ...args)](#pageevaluatepagefunction-args)
|
||||
@ -317,6 +318,11 @@ If there's no element matching `selector`, the method throws an error.
|
||||
#### page.close()
|
||||
- returns: <[Promise]>
|
||||
|
||||
#### page.content()
|
||||
- returns: <[Promise]<[String]>>
|
||||
|
||||
Gets the full HTML contents of the page, including the doctype.
|
||||
|
||||
#### page.emulate(options)
|
||||
- `options` <[Object]>
|
||||
- `viewport` <[Object]>
|
||||
|
14
lib/Page.js
14
lib/Page.js
@ -260,6 +260,20 @@ class Page extends EventEmitter {
|
||||
return this.mainFrame().url();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<String>}
|
||||
*/
|
||||
async content() {
|
||||
return await this.evaluate(() => {
|
||||
let retVal = '';
|
||||
if (document.doctype)
|
||||
retVal = new XMLSerializer().serializeToString(document.doctype);
|
||||
if (document.documentElement)
|
||||
retVal += document.documentElement.outerHTML;
|
||||
return retVal;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @return {!Promise}
|
||||
|
18
test/test.js
18
test/test.js
@ -1437,10 +1437,24 @@ describe('Page', function() {
|
||||
}));
|
||||
});
|
||||
describe('Page.setContent', function() {
|
||||
const expectedOutput = '<html><head></head><body><div>hello</div></body></html>';
|
||||
it('should work', SX(async function() {
|
||||
await page.setContent('<div>hello</div>');
|
||||
let result = await page.evaluate(() => document.body.innerHTML);
|
||||
expect(result).toBe('<div>hello</div>');
|
||||
let result = await page.content();
|
||||
expect(result).toBe(expectedOutput);
|
||||
}));
|
||||
it('should work with doctype', SX(async function() {
|
||||
const doctype = '<!DOCTYPE html>';
|
||||
await page.setContent(`${doctype}<div>hello</div>`);
|
||||
let result = await page.content();
|
||||
expect(result).toBe(`${doctype}${expectedOutput}`);
|
||||
}));
|
||||
it('should work with HTML 4 doctype', SX(async function() {
|
||||
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" ' +
|
||||
'"http://www.w3.org/TR/html4/strict.dtd">';
|
||||
await page.setContent(`${doctype}<div>hello</div>`);
|
||||
let result = await page.content();
|
||||
expect(result).toBe(`${doctype}${expectedOutput}`);
|
||||
}));
|
||||
});
|
||||
describe('Network Events', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user