Arson
Arson

Reputation: 193

How to prevent opening a new tab during scraping with puppeteer, when clicking a button with ng-click directive?

When scraping a website containing a button that navigates to a pdf file when clicked, I would normally remove target="_blank" attribute to prevent from opening in a new tab. However, this time around, clicking the button triggers some function like this: ng-click="$ctrl.openPriceList()", pdf gets open in a new tab and removing target attribute on button element does nothing. How to prevent opening in a new tab in such case?

Upvotes: 0

Views: 1136

Answers (1)

mbit
mbit

Reputation: 3023

You can override window.open:

((window, open) => {
    window.open = (url) => {
        open.call(window, url, '_self');
    };
})(window, window.open);

Upvotes: 2

Related Questions