Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

browser(firefox): make pipe work on Windows (#4058)

Pavel Feldman857abcfc10bc
diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBER
index 846e5ce449..a981b340e3 100644
--- a/browser_patches/firefox/BUILD_NUMBER
+++ b/browser_patches/firefox/BUILD_NUMBER
@@ -1,2 +1,2 @@
-1180
-Changed: [email protected] Fri Oct 2 09:36:06 PDT 2020
+1181
+Changed: [email protected] Mon, Oct 5, 2020 5:57:35 PM
diff --git a/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp b/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp
index 229b0a64d4..cd6b501e4e 100644
--- a/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp
+++ b/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp
@@ -25,14 +25,14 @@ namespace {
StaticRefPtr<nsRemoteDebuggingPipe> gPipe;
-const int readFD = 3;
-const int writeFD = 4;
-
const size_t kWritePacketSize = 1 << 16;
#if defined(_WIN32)
HANDLE readHandle;
HANDLE writeHandle;
+#else
+const int readFD = 3;
+const int writeFD = 4;
#endif
size_t ReadBytes(void* buffer, size_t size, bool exact_size)
@@ -107,8 +107,12 @@ nsresult nsRemoteDebuggingPipe::Init(nsIRemoteDebuggingPipeClient* aClient) {
MOZ_ALWAYS_SUCCEEDS(NS_NewNamedThread("Pipe Writer", getter_AddRefs(mWriterThread)));
#if defined(_WIN32)
- readHandle = reinterpret_cast<HANDLE>(_get_osfhandle(readFD));
- writeHandle = reinterpret_cast<HANDLE>(_get_osfhandle(writeFD));
+ CHAR pipeReadStr[20];
+ CHAR pipeWriteStr[20];
+ GetEnvironmentVariable("PW_PIPE_READ", pipeReadStr, 20);
+ GetEnvironmentVariable("PW_PIPE_WRITE", pipeWriteStr, 20);
+ readHandle = reinterpret_cast<HANDLE>(atoi(pipeReadStr));
+ writeHandle = reinterpret_cast<HANDLE>(atoi(pipeWriteStr));
#endif
MOZ_ALWAYS_SUCCEEDS(mReaderThread->Dispatch(NewRunnableMethod(
diff --git a/browser_patches/firefox/patches/bootstrap.diff b/browser_patches/firefox/patches/bootstrap.diff
index 110fb690d6..63790c96ab 100644
--- a/browser_patches/firefox/patches/bootstrap.diff
+++ b/browser_patches/firefox/patches/bootstrap.diff
@@ -58,6 +58,45 @@ index f042cc1081850ac60e329b70b5569f8b97d4e4dc..65bcff9b41b9471ef1427e3ea330481c
/**
* Return XPCOM wrapper for the internal accessible.
*/
+diff --git a/browser/app/winlauncher/LauncherProcessWin.cpp b/browser/app/winlauncher/LauncherProcessWin.cpp
+index 7a8b4a621dd4056dfde1f200c62cf629415cc6a4..e600b2cb78a769a460d27104e1dcb805dbd11ed7 100644
+--- a/browser/app/winlauncher/LauncherProcessWin.cpp
++++ b/browser/app/winlauncher/LauncherProcessWin.cpp
+@@ -21,6 +21,7 @@
+ #include "mozilla/WinHeaderOnlyUtils.h"
+ #include "nsWindowsHelpers.h"
+
++#include <io.h>
+ #include <windows.h>
+ #include <processthreadsapi.h>
+
+@@ -322,8 +323,25 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
+ HANDLE stdHandles[] = {::GetStdHandle(STD_INPUT_HANDLE),
+ ::GetStdHandle(STD_OUTPUT_HANDLE),
+ ::GetStdHandle(STD_ERROR_HANDLE)};
+-
+ attrs.AddInheritableHandles(stdHandles);
++ // Playwright pipe installation.
++ bool hasJugglerPipe =
++ mozilla::CheckArg(argc, argv, L"juggler-pipe",
++ static_cast<const wchar_t**>(nullptr),
++ mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND;
++ if (hasJugglerPipe && !mozilla::EnvHasValue("PW_PIPE_READ")) {
++ intptr_t stdio3 = _get_osfhandle(3);
++ intptr_t stdio4 = _get_osfhandle(4);
++ CHAR stdio3str[20];
++ CHAR stdio4str[20];
++ itoa(stdio3, stdio3str, 10);
++ itoa(stdio4, stdio4str, 10);
++ SetEnvironmentVariable("PW_PIPE_READ", stdio3str);
++ SetEnvironmentVariable("PW_PIPE_WRITE", stdio4str);
++ HANDLE pipeHandles[] = {reinterpret_cast<HANDLE>(stdio3),
++ reinterpret_cast<HANDLE>(stdio4)};
++ attrs.AddInheritableHandles(pipeHandles);
++ }
+
+ DWORD creationFlags = CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT;
+
diff --git a/browser/installer/allowed-dupes.mn b/browser/installer/allowed-dupes.mn
index 1e583f9fb014129d791d25b64a727021d6848105..6a91ef0bd0796abf99d8fd54ff6aede94aeb0807 100644
--- a/browser/installer/allowed-dupes.mn