Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response inter #447

Open
ddofborg opened this issue Jul 14, 2023 · 1 comment
Open

response inter #447

ddofborg opened this issue Jul 14, 2023 · 1 comment

Comments

@ddofborg
Copy link

ddofborg commented Jul 14, 2023

Versions:

    Python: 3.8.10
    __base_puppeteer_version__ = 'v1.6.0'
    __chromium_revision__ = '588429'
    version = '1.0.2'

I want to intercept AJAX responses (especially their return body). I use this code. This part asyncio.gather(response.text()) hangs and basically never finish.

Seems like a bug. Anyone with the same issue and some guidance for a solution?

import asyncio
from pyppeteer import launch

def intercept_response(response):
    print('>>>>')
    print("- URL:", response.url)
    print("- Method:", response.request.method)
    print("- Request Headers:", response.request.headers)
    print('---')
    print("- Response headers:", response.headers)
    print("- Response status:", response.status)
    print("- Response status:", response.body)
    print("- Response text:", asyncio.gather(response.text()) )
    print('<<<<')
    return

async def main()
    args = {}
    browser = await launch(**args)
    page = await browser.newPage()
    await page.goto('https://httpbin.org/')
    page.on('response', intercept_response)
@irfanykywz
Copy link

irfanykywz commented Mar 28, 2024

i success intercepeting response body ;3

        async def request_interception(response):
            """ await page.setRequestInterception(True) would block the flow, the interception is enabled individually """
            # enable interception
            response.__setattr__('_allowInterception', True)
            # print(response.ok)
            # print(response.request.method)
            if 'api/v4' in response.url:
                print(response.url)
                body = await response.text()
                print(body)

            return
        self.page.on('response', lambda req: asyncio.ensure_future(request_interception(req)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants