feat(Frame): Add addStyleTag API to frame - fixes #892 (#947)

This patch adds `Page.addStyleTag` and `Frame.addStyleTag` methods to the API.

Fixes #892.
This commit is contained in:
Sam Verschueren
2017-10-04 22:42:26 +02:00
committed by Andrey Lushnikov
parent d87480b609
commit 97e40e6823
5 changed files with 53 additions and 0 deletions

View File

@@ -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