Skip to content
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

Use one strategy for hiding and removing elements #46

Merged
merged 1 commit into from May 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const writeFile = promisify(fs.writeFile);

const isUrl = string => /^(https?|file):\/\/|^data:/.test(string);

const removeElements = elements => {
for (const element of elements) {
element.style.display = 'none';
}
};

const scrollToElement = (element, options) => {
const isOverflown = element => {
return (
Expand Down Expand Up @@ -245,12 +239,14 @@ const captureWebsite = async (input, options) => {

if (options.hideElements) {
await page.addStyleTag({
content: `${options.hideElements.join(', ')} { visibility: hidden; }`
content: `${options.hideElements.join(', ')} { visibility: hidden !important; }`
});
}

if (options.removeElements) {
await Promise.all(options.removeElements.map(selector => page.$$eval(selector, removeElements)));
await page.addStyleTag({
content: `${options.removeElements.join(' ')} { display: none !important; }`
});
}

if (options.clickElement) {
Expand Down