swoole_http_client 连接headless chrome的websocket 发送消息后会立即关闭连接

新手上路,请多包涵

问题描述

swoole_http_client 连接headless chrome的websocket 发送消息后会立即关闭连接

问题出现的环境背景及自己尝试过哪些方法

Google Chrome 版本 73.0.3683.103(正式版本) (64 位)
headless chrome启动方式 chrome.exe --blink-settings=imagesEnabled=false --headless --remote-debugging-port=9222
PHP版本:PHP 7.1.26 NTS
swoole版本: 4.2.12

相关代码

<?php

$cli = new swoole_http_client('localhost', 9222);

$cli->setHeaders([
    "Host" => 'localhost:9222',
    "Origin" => "chrome-search://local-ntp",
    "Cache-Control" => 'no-cache',
    "Accept-Language" => "zh,en-US;q=0.9,en;q=0.8,zh-TW;q=0.7,zh-CN;q=0.6",
    "Accept-Encoding" => 'gzip, deflate',
    'Pragma' => 'nocache',
    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
]);

$cli->on('message', function ($_cli, $frame) {
    var_dump($frame);
});

$cli->upgrade('/devtools/page/C64F564D4C2280D3CC0D59C4D1177CBB', function ($cli) {
    $cli->push('{"params": {"url": "https://github.com/fate0/pychrome"}, "method": "Page.navigate", "id": 1002}', WEBSOCKET_OPCODE_TEXT, true);
});


$cli->on('error', function($client) {
    var_dump($client);
});

$cli->on('close', function($clinet) {
    var_dump($clinet->errMsg);
});

你期待的结果是什么?实际看到的错误信息又是什么?

期待结果

curl http://localhost:9222/json

{
    "description": "",
    "devtoolsFrontendUrl": "/devtools/inspector.html?ws=10.208.53.120:9222/devtools/page/C64F564D4C2280D3CC0D59C4D1177CBB",
    "id": "C64F564D4C2280D3CC0D59C4D1177CBB",
    "title": "GitHub - fate0/pychrome: A Python Package for the Google Chrome Dev Protocol [threading base]",
    "type": "page",
    "url": "https://github.com/fate0/pychrome",
    "webSocketDebuggerUrl": "ws://10.208.53.120:9222/devtools/page/C64F564D4C2280D3CC0D59C4D1177CBB"
}

实际结果:

curl http://localhost:9222/json

[
    {
        "description": "",
        "devtoolsFrontendUrl": "/devtools/inspector.html?ws=10.208.53.120:9222/devtools/page/C64F564D4C2280D3CC0D59C4D1177CBB",
        "id": "C64F564D4C2280D3CC0D59C4D1177CBB",
        "title": "about:blank",
        "type": "page",
        "url": "about:blank",
        "webSocketDebuggerUrl": "ws://10.208.53.120:9222/devtools/page/C64F564D4C2280D3CC0D59C4D1177CBB"
    }
]
阅读 1.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题