ClericPy / ichrome

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.
https://pypi.org/project/ichrome/
MIT License
227 stars 29 forks source link

Modify of the Accept header #145

Open juhacz opened 8 months ago

juhacz commented 8 months ago

Is it possible to modify the Accept header sent by the browser? I need to modify the Accept header.

import asyncio
from ichrome import AsyncChromeDaemon

async def test():
    async with AsyncChromeDaemon() as cd:
        # create a new tab
        async with cd.connect_tab(index=None) as tab:
            await tab.set_headers({"Accept": "application/vnd.opbox-web.v2+json"})
            await tab.goto('https://httpbin.org/headers', timeout=5)
            print(await tab.html)

asyncio.run(test())

The above program does nothing when I change the line

await tab.set_headers({"Accept2": "application/vnd.opbox-web.v2+json"})

the Accept2 header is correctly addeded, strangely enough when I change the lines to

await tab.set_headers({"User-Agent": "application/vnd.opbox-web.v2+json"})

User Agent is changed, but this does not work in the case of the Accept header.

ClericPy commented 7 months ago
  1. maybe it's the feature of httpbin.org, try that use bottle/flask localhost?
  2. update new headers can be done with Fetch