pollyjs icon indicating copy to clipboard operation
pollyjs copied to clipboard

puppeteer adapter doesn't capture main frame

Open kiavashi opened this issue 8 years ago • 5 comments

I'm trying to use the puppeteer adapter to capture every request on a page (including the root html document, scripts, images, etc..) using:

requestResourceTypes: [
    'document', 'stylesheet', 'image', 'media', 'font', 'script', 'texttrack',
    'xhr', 'fetch', 'eventsource', 'websocket', 'manifest', 'other'
]

When requestResourceTypes includes document (which matches the main frame/html page), the page hangs indefinitely (or hits timeout)

Platform: macOS v10.11

Node.js: v8.11.4

@pollyjs/adapter-puppeteer: v1.2.0 @pollyjs/core: v1.2.0 @pollyjs/persister-fs: v1.2.0 puppeteer: v1.9.0

'use strict';

const {Polly} = require('@pollyjs/core');
const FSPersister = require('@pollyjs/persister-fs');
const PuppeteerAdapter = require('@pollyjs/adapter-puppeteer');
const puppeteer = require('puppeteer');

Polly.register(FSPersister);
Polly.register(PuppeteerAdapter);

(async () => {
    const browser = await puppeteer.launch({headless: false});
    const [page] = await browser.pages();

    await page.setRequestInterception(true);

    const polly = new Polly('hangs', {
        adapters: ['puppeteer'],
        adapterOptions: {
            puppeteer: {
                page,
                requestResourceTypes: [
                    'document'
                ]
            }
        },
        persister: 'fs',
        persisterOptions: {
            fs: {
                recordingsDir: `${__dirname}/recordings`
            }
        },
        recordFailedRequests: true,
        logging: true
    });

    await page.goto('http://www.example.com/', {
        waitUntil: 'networkidle2',
        timeout: 0
    });

    await page.close();
    await browser.close();
    await polly.stop();
})();

kiavashi avatar Oct 25 '18 19:10 kiavashi

Also, if I manually modify the recording.har file to add an entry for https://www.example.com/, it will correctly replay it. It's only when recording the request that it hangs.

kiavashi avatar Oct 25 '18 22:10 kiavashi

@kiavashps thanks for the detailed description on this issue. Does the page still hang if you set the resource types to ['xhr', 'fetch', 'document', 'other']?

offirgolan avatar Oct 28 '18 02:10 offirgolan

Polly does not currently capture all of those resource types. Only xhr, fetch, and other (partially) are supported resource types. Perhaps we should warn when other options are passed for requestResourceTypes.

Closing for now.

jasonmit avatar Nov 15 '18 06:11 jasonmit

I guess this is still the case. Are there any plans on adding support for the document resource type?

Yopi avatar Mar 23 '20 16:03 Yopi

Right now the scope of this project is to capture requests through xhr and fetch using the puppeteer adapter. In the future we may expand this to include other types.

jasonmit avatar Mar 23 '20 20:03 jasonmit