Skip to content

Intercepting requests #62

Closed
Closed

Description

@Matse2005

Hi first of all, thank you for this amazing project!

I have a question regarding request interception. I would like to intercept .m3u8 requests and access their URLs. For example, is something like the following javascript supported?

let m3u8;

await page.route('**/*.m3u8', route => {
  m3u8 = route.request().url();
  route.abort();
});

Is this approach supported in Playwright PHP? If so, what is the recommended way to implement this pattern so that I can capture the URL of .m3u8 files while aborting the request?

Thank you in advance for your guidance!

Activity

  1. smnandre commented on Jan 5, 2026

    @smnandre
    Member

    It absolutely does.

    Create a demo.php file

    <?php
    
    require __DIR__ . '/vendor/autoload.php';
    
    use Playwright\Network\RouteInterface;
    use Playwright\Playwright;
    
    $context = Playwright::chromium(['headless' => true]);
    $page = $context->newPage();
    
    $m3u8Url = null;
    
    $page->route('**/*.m3u8', function (RouteInterface $route) use (&$m3u8Url): void {
        $m3u8Url = $route->request()->url();
        $route->abort();
    });
    
    $html = <<<HTML
    <!doctype html>
    <html>
    <body>
    <script>
    fetch('https://example.com/video/playlist.m3u8').catch(() => {});
    </script>
    </body>
    </html>
    HTML;
    
    $page->goto('data:text/html,' . rawurlencode($html));
    $context->close();
    
    echo 'Captured m3u8 URL: ' . $m3u8Url;
    composer require playwright-php/playwright
    vendor/bin/playwright-install --browsers
    php demo.php
    Captured m3u8 URL: https://example.com/video/playlist.m3u8
    
  2. Matse2005 commented on Jan 7, 2026

    @Matse2005
    Author

    Thank you for the answer, after some changes it worked completely fine for my use case on my local machine. But when I added the app to my webserver the url is never extracted anymore it always fails. Does the package require some extra setup on Ubuntu? I've ran the install command again and I also ran the Playwright install-deps command.

  3. smnandre commented on Jan 7, 2026

    @smnandre
    Member

    CI tests pass on the Ubuntu runner.. without knowing if code are comparable.

    What exactly happens? Can you load the page? Is there anything in the console?

  4. locked and limited conversation to collaborators on Jan 28, 2026
  5. converted this issue into a discussion #63 on Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions