How to fix pyppeteer.errors.NetworkError: Request interception is not enabled.
Note: Also seeĀ Pyppetteer minimal network request interception example
Problem:
You are trying to intercept a request in Pyppeteer using
page.on('request', my_intercept_request)
but you’re getting an error message like this:
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
File "/usr/local/lib/python3.6/dist-packages/pyee/_compat.py", line 62, in _callback
self.emit('error', exc)
File "/usr/local/lib/python3.6/dist-packages/pyee/_base.py", line 106, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "/usr/local/lib/python3.6/dist-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
raise error
File "run.py", line 6, in intercept
await request.continue_()
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/network_manager.py", line 481, in continue_
raise NetworkError('Request interception is not enabled.')
pyppeteer.errors.NetworkError: Request interception is not enabled.
Solution
Add
await page.setRequestInterception(True)
directly after your call to
page = await browser.newPage()
This will enable request interception and your code will run just fine.