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

chrome connected | ws has been closed #97

Closed snja closed 2 years ago

snja commented 2 years ago

ERROR 2022-07-23 04:06:20 [ichrome] async_utils.py(561): Receive the <WSMsgType.ERROR: 258> message which break the recv daemon: "Message size 23239060 exceeds limit 20971520".

after run the code

async def iframe_q(self, iframe_selector, selector, action="", variable=""):
        var_ = "item.result = el.%s" % variable if variable else ""
        act = "el.%s" % action if action else ""
        JS = '''
        var cd = document.querySelector('%s').contentDocument
        var el = cd.querySelector('%s')
        var item = {
            tagName: el.tagName,
            innerHTML: el.innerHTML,
            outerHTML: el.outerHTML,
            textContent: el.textContent,
            result: "",
            attributes: {}
        }
        %s
        %s
        for (const attr of el.attributes) item.attributes[attr.name] = attr.value
        JSON.stringify(item)
        ''' % (iframe_selector, selector, act, var_)
        try:
            res = await self.tab.js(JS, 'result.result.value', timeout=1)
            print(res)
            arg = json.loads(res)
            tag = Tag(**arg)
            return tag
        except Exception as e:
            return None
ClericPy commented 2 years ago

Receive the <WSMsgType.ERROR: 258> message which break the recv daemon: "Message size 23239060 exceeds limit 20971520".

The error log means you need to increase the max_size(AsyncTab._DEFAULT_WS_KWARGS)

_DEFAULT_WS_KWARGS: Dict = {"max_msg_size": 20 * 1024**2} 20MB is not large enough, try changing it to 1024 * 1024**2

https://github.com/ClericPy/ichrome/blob/master/ichrome/async_utils.py#L290