Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Block certain resources from loading #136

Answered by petsoukos
petsoukos asked this question in Q&A
Discussion options

You must be logged in to vote

Well, to answer my own question.

I managed to block it with the following code

        $page->setRequestInterception(true);
        $page->on('request', JsFunction::createWithParameters(['request'])
            ->body("
            if(request.url().endsWith('.jpg') || request.url().endsWith('.png') || request.url().endsWith('.jpeg')) {
                request.abort();
            } else if(request.resourceType() === 'stylesheet') {
                request.abort();
            } else if(['google-analytics'].some(resource => request.url().indexOf(resource) !== -1)) {
                request.abort();
            } else {
                request.continue();
            }
            "));

I'm…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by petsoukos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant