X
X
xcuube2019-10-22 13:46:12
JavaScript
xcuube, 2019-10-22 13:46:12

How to close the puppeteer browser?

Good afternoon! How can you close the puppeteer browser in this code?
I know it's done via browser.close();, but I just don't have access to it.
(in the code I marked the place where you need to close the browser)

puppeteer.launch(
            {
                args: [
                    '--proxy-server=ip:port', // Or whatever the address is
                ]
            }
        )
        .then(function(browser) {
            return browser.newPage();
        })
        .then(function(page) {
            page.authenticate({
                username: 'log',
                password: 'pass',
            });
            return page.goto(desktopUrl).then(function() {
                return page.content();
            });
        })
        .then(function(html) {

            const productList = [];

            $('div.product-card', html).each(function() {
                let link = $("a.card-link", $(this)).attr("href");
                let pic = $("img.image-component", $(this)).attr("src");
                productList.push({ProductLink: link, picture: pic});
            });

            console.log(productList);

//----------Где-то тут нужно закрыть браузер
            
            return callback(null, productList);
        })
        .catch(function(err) {
            return callback(err, null);
        });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question