src/api/instagram.js
/**
     * Open a post in a new page, then extract its metadata
     */
Open a post in a new page, then extract its metadata
Open a post in a new page then extract its metadata
async postPage(post, retries) {
        const postPage = await this.browser.newPage();
        await postPage.setRequestInterception(true);
        postPage.on("request", async (req) => {
            if (!req.url().includes("/p/" + post)) {
                await req.abort();
            }
            else {
                await req.continue();
            }
        });
        postPage.on("requestfailed", async () => undefined);
        let data;
        let parsed;
        try {
            await postPage.goto(this.postURL + post);
            data = await postPage.evaluate(() => {
                return JSON.stringify(window["_sharedData"].entry_data.PostPage[0].graphql);
            });
            parsed = JSON.parse(data);
            await postPage.close();
        }
        catch (e) {
            this.logger.error(e);
            await this.progress(Progress.ABORTED);
            await this.sleep(2);
            await postPage.close();
            if (retries > 0) {
                await this.postPage(post, --retries);
            }
        }
        if (!parsed) {
            return;
        }
        await this.executePlugins("postPage", parsed);
        await this.addToPostBuffer(parsed);
    }
async postPage ( post , retries ) { const postPage = await this . browser . newPage ( ) ; await postPage . setRequestInterception ( true ) ; postPage . on ( "request" , async ( req ) => { if ( ! req . url ( ) . includes ( "/p/" + post ) ) { await req . abort ( ) ; } else { await req . continue ( ) ; } } ) ; postPage . on ( "requestfailed" , async ( ) => undefined ) ; let data ; let parsed ; try { await postPage . goto ( this . postURL + post ) ; data = await postPage . evaluate ( ( ) => { return JSON . stringify ( window [ "_sharedData" ] . entry_data . PostPage [ 0 ] . graphql ) ; } ) ; parsed = JSON . parse ( data ) ; await postPage . close ( ) ; } catch ( e ) { this . logger . error ( e ) ; await this . progress ( Progress . ABORTED ) ; await this . sleep ( 2 ) ; await postPage . close ( ) ; if ( retries > 0 ) { await this . postPage ( post , -- retries ) ; } } if ( ! parsed ) { return ; } await this . executePlugins ( "postPage" , parsed ) ; await this . addToPostBuffer ( parsed ) ; }
Open a post in a new page, then extract its metadata
Open a post in a new page then extract its metadata
// Create page // Visit post and read state // Load data from memory /* istanbul ignore next */ // Log error and wait // Close existing attempt // Retry