mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
This patch adds `Page.addStyleTag` and `Frame.addStyleTag` methods to the API. Fixes #892.
This commit is contained in:
committed by
Andrey Lushnikov
parent
d87480b609
commit
97e40e6823
@@ -358,6 +358,25 @@ class Frame {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
*/
|
||||
async addStyleTag(url) {
|
||||
return this.evaluate(addStyleTag, url);
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
*/
|
||||
function addStyleTag(url) {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = url;
|
||||
const promise = new Promise(x => link.onload = x);
|
||||
document.head.appendChild(link);
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(string|number|function())} selectorOrTimeout
|
||||
* @param {!Object=} options
|
||||
|
||||
Reference in New Issue
Block a user