MCPcopy Create free account
hub / github.com/Artikash/Textractor / Start

Function Start

extensions/devtools.cpp:34–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 QMetaObject::invokeMethod(statusLabel, std::bind(&QLabel::setText, statusLabel, status));
33 }
34 void Start(std::wstring chromePath, bool headless)
35 {
36 if (process) DevTools::Close();
37
38 auto args = FormatString(
39 L"%s --proxy-server=direct:// --disable-extensions --disable-gpu --user-data-dir=%s\\devtoolscache --remote-debugging-port=9222",
40 chromePath,
41 std::filesystem::current_path().wstring()
42 );
43 if (headless) args += L" --headless";
44 DWORD exitCode = 0;
45 STARTUPINFOW DUMMY = { sizeof(DUMMY) };
46 PROCESS_INFORMATION processInfo = {};
47 if (!CreateProcessW(NULL, args.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &DUMMY, &processInfo)) return StatusChanged("StartupFailed");
48 CloseHandle(processInfo.hThread);
49 process = processInfo.hProcess;
50
51 if (HttpRequest httpRequest{
52 L"Mozilla/5.0 Textractor",
53 L"127.0.0.1",
54 L"POST",
55 L"/json/list",
56 "",
57 NULL,
58 9222,
59 NULL,
60 WINHTTP_FLAG_ESCAPE_DISABLE
61 })
62 if (auto list = Copy(JSON::Parse(httpRequest.response).Array())) if (auto it = std::find_if(
63 list->begin(),
64 list->end(),
65 [](const JSON::Value<wchar_t>& object) { return object[L"type"].String() && *object[L"type"].String() == L"page" && object[L"webSocketDebuggerUrl"].String(); }
66 ); it != list->end()) return webSocket.open(S(*(*it)[L"webSocketDebuggerUrl"].String()));
67
68 StatusChanged("ConnectingFailed");
69 }
70
71 auto _ = ([]
72 {

Callers 1

InitializeFunction · 0.70

Calls 8

CloseFunction · 0.85
FormatStringFunction · 0.85
StatusChangedFunction · 0.85
CopyFunction · 0.85
SFunction · 0.85
ArrayMethod · 0.80
StringMethod · 0.80
ParseFunction · 0.70

Tested by

no test coverage detected