Skip to content

Commit

Permalink
fix(browserType): fix ignore all default arguments (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Jan 11, 2021
1 parent 8ba8f8f commit 1f29b09
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 43 deletions.
20 changes: 20 additions & 0 deletions src/PlaywrightSharp.Tests/BrowserTypeLaunchTests.cs
Expand Up @@ -186,5 +186,25 @@ public async Task ShouldValidateFirefoxUserPrefs()

await Assert.ThrowsAsync<ArgumentException>(() => BrowserType.LaunchPersistentContextAsync("foo", options));
}

/// <summary>
/// PuppeteerSharp test. It's not in upstream
/// </summary>
[SkipBrowserAndPlatformFact(skipFirefox: true, skipWebkit: true)]
public async Task ShouldWorkWithIgnoreDefaultArgs()
{
var options = TestConstants.GetDefaultBrowserOptions();
options.IgnoreAllDefaultArgs = true;
options.Args = new[]
{
"--remote-debugging-pipe",
"--headless",
"--hide-scrollbars",
"--mute-audio",
"--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4"
};

await using var browser = await BrowserType.LaunchAsync(options);
}
}
}
18 changes: 9 additions & 9 deletions src/PlaywrightSharp/BrowserType.cs
Expand Up @@ -59,8 +59,8 @@ internal BrowserType(IChannelOwner parent, string guid, BrowserTypeInitializer i
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
Dictionary<string, object> firefoxUserPrefs = null,
ProxySettings proxy = null,
Expand All @@ -80,8 +80,8 @@ internal BrowserType(IChannelOwner parent, string guid, BrowserTypeInitializer i
Timeout = timeout,
DumpIO = dumpIO,
SlowMo = slowMo,
IgnoreAllDefaultArgs = ignoreAllDefaultArgs,
IgnoreDefaultArgs = ignoreDefaultArgs,
IgnoredDefaultArgs = ignoredDefaultArgs,
Env = env,
FirefoxUserPrefs = firefoxUserPrefs,
Proxy = proxy,
Expand Down Expand Up @@ -115,8 +115,8 @@ public async Task<IBrowser> LaunchAsync(LaunchOptions options = null)
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down Expand Up @@ -154,8 +154,8 @@ public async Task<IBrowser> LaunchAsync(LaunchOptions options = null)
Timeout = timeout,
DumpIO = dumpIO,
SlowMo = slowMo,
IgnoreAllDefaultArgs = ignoreAllDefaultArgs,
IgnoreDefaultArgs = ignoreDefaultArgs,
IgnoredDefaultArgs = ignoredDefaultArgs,
Env = env,
Proxy = proxy,
Viewport = viewport,
Expand Down Expand Up @@ -194,8 +194,8 @@ public async Task<IBrowser> LaunchAsync(LaunchOptions options = null)
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down Expand Up @@ -233,8 +233,8 @@ public async Task<IBrowser> LaunchAsync(LaunchOptions options = null)
Timeout = timeout,
DumpIO = dumpIO,
SlowMo = slowMo,
IgnoreAllDefaultArgs = ignoreAllDefaultArgs,
IgnoreDefaultArgs = ignoreDefaultArgs,
IgnoredDefaultArgs = ignoredDefaultArgs,
Env = env,
Proxy = proxy,
UserAgent = userAgent,
Expand Down
18 changes: 9 additions & 9 deletions src/PlaywrightSharp/Chromium/ChromiumBrowserType.cs
Expand Up @@ -29,8 +29,8 @@ public new async Task<IChromiumBrowser> LaunchAsync(LaunchOptions options)
int? timeout,
bool? dumpIO,
int? slowMo,
bool? ignoreDefaultArgs,
string[] ignoredDefaultArgs,
bool? ignoreAllDefaultArgs,
string[] ignoreDefaultArgs,
Dictionary<string, string> env,
Dictionary<string, object> firefoxUserPrefs,
ProxySettings proxy,
Expand All @@ -49,8 +49,8 @@ public new async Task<IChromiumBrowser> LaunchAsync(LaunchOptions options)
timeout,
dumpIO,
slowMo,
ignoreAllDefaultArgs,
ignoreDefaultArgs,
ignoredDefaultArgs,
env,
firefoxUserPrefs,
proxy,
Expand All @@ -76,8 +76,8 @@ public new async Task<IChromiumBrowserContext> LaunchPersistentContextAsync(stri
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down Expand Up @@ -113,8 +113,8 @@ public new async Task<IChromiumBrowserContext> LaunchPersistentContextAsync(stri
timeout,
dumpIO,
slowMo,
ignoreAllDefaultArgs,
ignoreDefaultArgs,
ignoredDefaultArgs,
env,
proxy,
userAgent,
Expand Down Expand Up @@ -151,8 +151,8 @@ public new async Task<IChromiumBrowserContext> LaunchPersistentContextAsync(stri
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down Expand Up @@ -187,8 +187,8 @@ public new async Task<IChromiumBrowserContext> LaunchPersistentContextAsync(stri
timeout,
dumpIO,
slowMo,
ignoreAllDefaultArgs,
ignoreDefaultArgs,
ignoredDefaultArgs,
env,
proxy,
userAgent,
Expand Down
8 changes: 4 additions & 4 deletions src/PlaywrightSharp/Chromium/IChromiumBrowserType.cs
Expand Up @@ -22,8 +22,8 @@ public interface IChromiumBrowserType : IBrowserType
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
Dictionary<string, object> firefoxUserPrefs = null,
ProxySettings proxy = null,
Expand All @@ -48,8 +48,8 @@ public interface IChromiumBrowserType : IBrowserType
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down
24 changes: 12 additions & 12 deletions src/PlaywrightSharp/IBrowserType.cs
Expand Up @@ -39,9 +39,9 @@ public interface IBrowserType
/// <param name="timeout">Maximum time in milliseconds to wait for the browser instance to start.</param>
/// <param name="dumpIO">Whether to pipe browser process stdout and stderr into process.stdout and process.stderr. Defaults to false.</param>
/// <param name="slowMo">Slows down PlaywrightSharp operations by the specified amount of milliseconds. Useful so that you can see what is going on.</param>
/// <param name="ignoreDefaultArgs">If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// <param name="ignoreAllDefaultArgs">If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// Dangerous option; use with care. Defaults to false.</param>
/// <param name="ignoredDefaultArgs">if <paramref name="ignoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.</param>
/// <param name="ignoreDefaultArgs">if <paramref name="ignoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.</param>
/// <param name="env">Specify environment variables that will be visible to browser. Defaults to Environment variables.</param>
/// <param name="firefoxUserPrefs">Firefox user preferences. Learn more about the Firefox user preferences at about:config.</param>
/// <param name="proxy">Network proxy settings.</param>
Expand All @@ -61,8 +61,8 @@ public interface IBrowserType
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
Dictionary<string, object> firefoxUserPrefs = null,
ProxySettings proxy = null,
Expand Down Expand Up @@ -93,9 +93,9 @@ public interface IBrowserType
/// <param name="timeout">Maximum time in milliseconds to wait for the browser instance to start.</param>
/// <param name="dumpIO">Whether to pipe browser process stdout and stderr into process.stdout and process.stderr. Defaults to false.</param>
/// <param name="slowMo">Slows down PlaywrightSharp operations by the specified amount of milliseconds. Useful so that you can see what is going on.</param>
/// <param name="ignoreDefaultArgs">If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// <param name="ignoreAllDefaultArgs">If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// Dangerous option; use with care. Defaults to false.</param>
/// <param name="ignoredDefaultArgs">if <paramref name="ignoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.</param>
/// <param name="ignoreDefaultArgs">if <paramref name="ignoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.</param>
/// <param name="env">Specify environment variables that will be visible to browser. Defaults to Environment variables.</param>
/// <param name="proxy">Network proxy settings.</param>
/// <param name="userAgent">Specific user agent to use in this context.</param>
Expand Down Expand Up @@ -135,8 +135,8 @@ public interface IBrowserType
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down Expand Up @@ -174,9 +174,9 @@ public interface IBrowserType
/// <param name="timeout">Maximum time in milliseconds to wait for the browser instance to start.</param>
/// <param name="dumpIO">Whether to pipe browser process stdout and stderr into process.stdout and process.stderr. Defaults to false.</param>
/// <param name="slowMo">Slows down PlaywrightSharp operations by the specified amount of milliseconds. Useful so that you can see what is going on.</param>
/// <param name="ignoreDefaultArgs">If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// <param name="ignoreAllDefaultArgs">If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// Dangerous option; use with care. Defaults to false.</param>
/// <param name="ignoredDefaultArgs">if <paramref name="ignoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.</param>
/// <param name="ignoreDefaultArgs">if <paramref name="ignoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.</param>
/// <param name="env">Specify environment variables that will be visible to browser. Defaults to Environment variables.</param>
/// <param name="proxy">Network proxy settings.</param>
/// <param name="userAgent">Specific user agent to use in this context.</param>
Expand Down Expand Up @@ -215,8 +215,8 @@ public interface IBrowserType
int? timeout = null,
bool? dumpIO = null,
int? slowMo = null,
bool? ignoreDefaultArgs = null,
string[] ignoredDefaultArgs = null,
bool? ignoreAllDefaultArgs = null,
string[] ignoreDefaultArgs = null,
Dictionary<string, string> env = null,
ProxySettings proxy = null,
string userAgent = null,
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp/LaunchOptions.cs
Expand Up @@ -31,8 +31,8 @@ public LaunchPersistentOptions ToPersistentOptions()
Timeout = Timeout,
DumpIO = DumpIO,
SlowMo = SlowMo,
IgnoreAllDefaultArgs = IgnoreAllDefaultArgs,
IgnoreDefaultArgs = IgnoreDefaultArgs,
IgnoredDefaultArgs = IgnoredDefaultArgs,
Env = Env,
Proxy = Proxy,
ChromiumSandbox = ChromiumSandbox,
Expand Down
17 changes: 9 additions & 8 deletions src/PlaywrightSharp/LaunchOptionsBase.cs
Expand Up @@ -62,7 +62,7 @@ public abstract class LaunchOptionsBase
/// If true, Playwright does not pass its own configurations args and only uses the ones from args.
/// Dangerous option; use with care. Defaults to false.
/// </summary>
public bool? IgnoreDefaultArgs { get; set; }
public bool? IgnoreAllDefaultArgs { get; set; }

/// <summary>
/// Close the browser process on Ctrl-C. Defaults to true.
Expand All @@ -84,10 +84,10 @@ public abstract class LaunchOptionsBase
/// </summary>
public bool? ChromiumSandbox { get; set; }

/// <summary>
/// if <see cref="IgnoreDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.
/// <summary>ß
/// if <see cref="IgnoreAllDefaultArgs"/> is set to <c>false</c> this list will be used to filter default arguments.
/// </summary>
public string[] IgnoredDefaultArgs { get; set; }
public string[] IgnoreDefaultArgs { get; set; }

/// <summary>
/// Specify environment variables that will be visible to browser. Defaults to Environment variables.
Expand Down Expand Up @@ -153,13 +153,14 @@ public abstract class LaunchOptionsBase
args["slowMo"] = SlowMo;
}

if (IgnoreDefaultArgs != null)
if (IgnoreAllDefaultArgs != null && IgnoreDefaultArgs == null)
{
args["ignoreDefaultArgs"] = IgnoreDefaultArgs;
args["ignoreAllDefaultArgs"] = IgnoreAllDefaultArgs;
}
else if (IgnoredDefaultArgs != null)

if (IgnoreDefaultArgs != null)
{
args["ignoreDefaultArgs"] = IgnoredDefaultArgs;
args["ignoreDefaultArgs"] = IgnoreDefaultArgs;
}

if (Env != null)
Expand Down

0 comments on commit 1f29b09

Please sign in to comment.