internal Task SetHttpCredentialsAsync(HttpCredentials credentials) => Connection.SendMessageToServerAsync <PageChannel>( Guid, "setHTTPCredentials", new Dictionary <string, object> { ["httpCredentials"] = credentials, });
internal Task <BrowserContextChannel> NewContextAsync( bool?acceptDownloads = null, bool?bypassCSP = null, ColorScheme colorScheme = ColorScheme.Undefined, float?deviceScaleFactor = null, IEnumerable <KeyValuePair <string, string> > extraHTTPHeaders = null, Geolocation geolocation = null, bool?hasTouch = null, HttpCredentials httpCredentials = null, bool?ignoreHTTPSErrors = null, bool?isMobile = null, bool?javaScriptEnabled = null, string locale = null, bool?offline = null, IEnumerable <string> permissions = null, Proxy proxy = null, bool?recordHarOmitContent = null, string recordHarPath = null, string recordVideoDir = null, RecordVideoSize recordVideoSize = null, string storageState = null, string storageStatePath = null, string timezoneId = null, string userAgent = null, ViewportSize viewportSize = default) { var args = new Dictionary <string, object>(); if (acceptDownloads.HasValue) { args.Add("acceptDownloads", acceptDownloads.Value); } if (bypassCSP.HasValue) { args.Add("bypassCSP", bypassCSP.Value); } if (colorScheme != ColorScheme.Undefined) { args.Add("colorScheme", colorScheme); } if (deviceScaleFactor.HasValue) { args.Add("deviceScaleFactor", deviceScaleFactor.Value); } if (extraHTTPHeaders != null) { args["extraHTTPHeaders"] = extraHTTPHeaders.Select(kv => new HeaderEntry { Name = kv.Key, Value = kv.Value }).ToArray(); } if (geolocation != null) { args.Add("geolocation", geolocation); } if (hasTouch.HasValue) { args.Add("hasTouch", hasTouch.Value); } if (httpCredentials != null) { args.Add("httpCredentials", httpCredentials); } if (ignoreHTTPSErrors.HasValue) { args.Add("ignoreHTTPSErrors", ignoreHTTPSErrors.Value); } if (isMobile.HasValue) { args.Add("isMobile", isMobile.Value); } if (javaScriptEnabled.HasValue) { args.Add("javaScriptEnabled", javaScriptEnabled.Value); } if (!string.IsNullOrEmpty(locale)) { args.Add("locale", locale); } if (offline.HasValue) { args.Add("offline", offline.Value); } if (permissions != null) { args.Add("permissions", permissions); } if (proxy != null) { args.Add("proxy", proxy); } if (!string.IsNullOrEmpty(recordHarPath)) { args.Add("recordHar", new { Path = recordHarPath, OmitContent = recordHarOmitContent, }); } if (!string.IsNullOrEmpty(recordVideoDir) && recordVideoDir != null) { args.Add("recordVideo", new Dictionary <string, object>() { { "dir", recordVideoDir }, { "size", recordVideoSize }, }); } if (!string.IsNullOrEmpty(storageState)) { args.Add("storageState", storageState); } if (!string.IsNullOrEmpty(storageStatePath)) { args.Add("storageStatePath", storageStatePath); } if (!string.IsNullOrEmpty(timezoneId)) { args.Add("timezoneId", timezoneId); } if (!string.IsNullOrEmpty(userAgent)) { args.Add("userAgent", userAgent); } if (ViewportSize.NoViewport.Equals(viewportSize)) { args.Add("noDefaultViewport", true); } else if (viewportSize != null && !ViewportSize.Default.Equals(viewportSize)) { args.Add("viewport", viewportSize); } args["sdkLanguage"] = "csharp"; return(Connection.SendMessageToServerAsync <BrowserContextChannel>( Guid, "newContext", args, true)); }
internal Task <BrowserContextChannel> LaunchPersistentContextAsync( string userDataDir, bool?headless = default, Microsoft.Playwright.BrowserChannel channel = default, string executablePath = default, IEnumerable <string> args = default, Proxy proxy = default, string downloadsPath = default, bool?chromiumSandbox = default, bool?handleSIGINT = default, bool?handleSIGTERM = default, bool?handleSIGHUP = default, float?timeout = default, IEnumerable <KeyValuePair <string, string> > env = default, bool?devtools = default, float?slowMo = default, bool?acceptDownloads = default, bool?ignoreHTTPSErrors = default, bool?bypassCSP = default, ViewportSize viewportSize = default, ScreenSize screenSize = default, string userAgent = default, float?deviceScaleFactor = default, bool?isMobile = default, bool?hasTouch = default, bool?javaScriptEnabled = default, string timezoneId = default, Geolocation geolocation = default, string locale = default, IEnumerable <string> permissions = default, IEnumerable <KeyValuePair <string, string> > extraHTTPHeaders = default, bool?offline = default, HttpCredentials httpCredentials = default, ColorScheme colorScheme = default, string recordHarPath = default, bool?recordHarOmitContent = default, string recordVideoDir = default, RecordVideoSize recordVideoSize = default, IEnumerable <string> ignoreDefaultArgs = default, bool?ignoreAllDefaultArgs = default) { var channelArgs = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(userDataDir)) { channelArgs.Add("userDataDir", userDataDir); } if (headless.HasValue) { channelArgs.Add("headless", headless); } if (channel != Microsoft.Playwright.BrowserChannel.Undefined) { channelArgs.Add("channel", channel); } if (!string.IsNullOrEmpty(executablePath)) { channelArgs.Add("executablePath", executablePath); } if (args?.Any() == true) { channelArgs.Add("args", args); } if (!string.IsNullOrEmpty(downloadsPath)) { channelArgs.Add("downloadsPath", downloadsPath); } if (proxy != null) { channelArgs.Add("proxy", proxy); } if (chromiumSandbox.HasValue) { channelArgs.Add("chromiumSandbox", chromiumSandbox); } if (handleSIGINT.HasValue) { channelArgs.Add("handleSIGINT", handleSIGINT); } if (handleSIGTERM.HasValue) { channelArgs.Add("handleSIGTERM", handleSIGTERM); } if (handleSIGHUP.HasValue) { channelArgs.Add("handleSIGHUP", handleSIGHUP); } if (timeout.HasValue) { channelArgs.Add("timeout", timeout); } if (env?.Any() == true) { channelArgs.Add("env", env.Remap()); } if (devtools.HasValue) { channelArgs.Add("devtools", devtools); } if (slowMo.HasValue) { channelArgs.Add("slowMo", slowMo); } if (acceptDownloads.HasValue) { channelArgs.Add("acceptDownloads", acceptDownloads); } if (ignoreHTTPSErrors.HasValue) { channelArgs.Add("ignoreHTTPSErrors", ignoreHTTPSErrors); } if (bypassCSP.HasValue) { channelArgs.Add("bypassCSP", bypassCSP); } if (ViewportSize.NoViewport.Equals(viewportSize)) { channelArgs.Add("noDefaultViewport", true); } else if (viewportSize != null && !ViewportSize.Default.Equals(viewportSize)) { channelArgs.Add("viewport", viewportSize); } if (screenSize != default) { channelArgs.Add("screensize", screenSize); } if (!string.IsNullOrEmpty(userAgent)) { channelArgs.Add("userAgent", userAgent); } if (deviceScaleFactor.HasValue) { channelArgs.Add("deviceScaleFactor", deviceScaleFactor); } if (isMobile.HasValue) { channelArgs.Add("isMobile", isMobile); } if (hasTouch.HasValue) { channelArgs.Add("hasTouch", hasTouch); } if (javaScriptEnabled.HasValue) { channelArgs.Add("javaScriptEnabled", javaScriptEnabled); } if (!string.IsNullOrEmpty(timezoneId)) { channelArgs.Add("timezoneId", timezoneId); } if (geolocation != default) { channelArgs.Add("geolocation", geolocation); } if (!string.IsNullOrEmpty(locale)) { channelArgs.Add("locale", locale); } if (permissions != null && permissions.Any()) { channelArgs.Add("permissions", permissions); } if (extraHTTPHeaders != null && extraHTTPHeaders.Any()) { channelArgs.Add("extraHTTPHeaders", extraHTTPHeaders.Remap()); } if (offline.HasValue) { channelArgs.Add("offline", offline); } if (httpCredentials != default) { channelArgs.Add("httpCredentials", httpCredentials); } if (colorScheme != ColorScheme.Undefined) { channelArgs.Add("colorScheme", colorScheme); } if (!string.IsNullOrEmpty(recordHarPath)) { channelArgs.Add("recordHar", new { Path = recordHarPath, OmitContent = recordHarOmitContent.GetValueOrDefault(false), }); } if (!string.IsNullOrEmpty(recordVideoDir) && recordVideoDir != null) { channelArgs.Add("recordVideo", new Dictionary <string, object>() { { "dir", recordVideoDir }, { "size", recordVideoSize }, }); } if (ignoreDefaultArgs != null && ignoreDefaultArgs.Any()) { channelArgs.Add("ignoreDefaultArgs", ignoreDefaultArgs); } if (ignoreAllDefaultArgs.HasValue) { channelArgs.Add("ignoreAllDefaultArgs", ignoreAllDefaultArgs); } channelArgs.Add("sdkLanguage", "csharp"); return(Connection.SendMessageToServerAsync <BrowserContextChannel>(Guid, "launchPersistentContext", channelArgs, false)); }
internal Task <BrowserContextChannel> NewContextAsync( bool?acceptDownloads = null, bool?bypassCSP = null, ColorScheme?colorScheme = null, ReducedMotion?reducedMotion = null, ForcedColors?forcedColors = null, float?deviceScaleFactor = null, IEnumerable <KeyValuePair <string, string> > extraHTTPHeaders = null, Geolocation geolocation = null, bool?hasTouch = null, HttpCredentials httpCredentials = null, bool?ignoreHTTPSErrors = null, bool?isMobile = null, bool?javaScriptEnabled = null, string locale = null, bool?offline = null, IEnumerable <string> permissions = null, Proxy proxy = null, bool?recordHarOmitContent = null, string recordHarPath = null, Dictionary <string, object> recordVideo = null, string storageState = null, string storageStatePath = null, string timezoneId = null, string userAgent = null, ViewportSize viewportSize = default, ScreenSize screenSize = default, string baseUrl = default, bool?strictSelectors = default) { var args = new Dictionary <string, object> { { "acceptDownloads", acceptDownloads }, { "bypassCSP", bypassCSP }, { "colorScheme", colorScheme }, { "reducedMotion", reducedMotion }, { "deviceScaleFactor", deviceScaleFactor }, }; if (extraHTTPHeaders != null) { args["extraHTTPHeaders"] = extraHTTPHeaders.Select(kv => new HeaderEntry { Name = kv.Key, Value = kv.Value }).ToArray(); } args.Add("geolocation", geolocation); args.Add("hasTouch", hasTouch); args.Add("httpCredentials", httpCredentials); args.Add("ignoreHTTPSErrors", ignoreHTTPSErrors); args.Add("isMobile", isMobile); args.Add("javaScriptEnabled", javaScriptEnabled); args.Add("locale", locale); args.Add("offline", offline); args.Add("permissions", permissions); args.Add("proxy", proxy); args.Add("strictSelectors", strictSelectors); args.Add("forcedColors", forcedColors); if (!string.IsNullOrEmpty(recordHarPath)) { args.Add("recordHar", new { Path = recordHarPath, OmitContent = recordHarOmitContent, }); } if (recordVideo != null) { args.Add("recordVideo", recordVideo); } if (!string.IsNullOrEmpty(storageStatePath)) { if (!File.Exists(storageStatePath)) { throw new PlaywrightException($"The specified storage state file does not exist: {storageStatePath}"); } storageState = File.ReadAllText(storageStatePath); } if (!string.IsNullOrEmpty(storageState)) { args.Add("storageState", JsonSerializer.Deserialize <StorageState>(storageState, Helpers.JsonExtensions.DefaultJsonSerializerOptions)); } args.Add("timezoneId", timezoneId); args.Add("userAgent", userAgent); if (viewportSize?.Width == -1) { args.Add("noDefaultViewport", true); } else { args.Add("viewport", viewportSize); args.Add("screen", screenSize); } args.Add("baseURL", baseUrl); return(Connection.SendMessageToServerAsync <BrowserContextChannel>( Guid, "newContext", args)); }
internal Task <BrowserContextChannel> LaunchPersistentContextAsync( string userDataDir, bool?headless = default, string channel = default, string executablePath = default, IEnumerable <string> args = default, Proxy proxy = default, string downloadsPath = default, string tracesDir = default, bool?chromiumSandbox = default, bool?handleSIGINT = default, bool?handleSIGTERM = default, bool?handleSIGHUP = default, float?timeout = default, IEnumerable <KeyValuePair <string, string> > env = default, bool?devtools = default, float?slowMo = default, bool?acceptDownloads = default, bool?ignoreHTTPSErrors = default, bool?bypassCSP = default, ViewportSize viewportSize = default, ScreenSize screenSize = default, string userAgent = default, float?deviceScaleFactor = default, bool?isMobile = default, bool?hasTouch = default, bool?javaScriptEnabled = default, string timezoneId = default, Geolocation geolocation = default, string locale = default, IEnumerable <string> permissions = default, IEnumerable <KeyValuePair <string, string> > extraHTTPHeaders = default, bool?offline = default, HttpCredentials httpCredentials = default, ColorScheme?colorScheme = default, ReducedMotion?reducedMotion = default, ForcedColors?forcedColors = default, string recordHarPath = default, bool?recordHarOmitContent = default, Dictionary <string, object> recordVideo = default, IEnumerable <string> ignoreDefaultArgs = default, bool?ignoreAllDefaultArgs = default, string baseUrl = default, bool?strictSelectors = default) { var channelArgs = new Dictionary <string, object> { { "userDataDir", userDataDir }, { "headless", headless }, { "channel", channel }, { "executablePath", executablePath }, { "args", args }, { "downloadsPath", downloadsPath }, { "tracesDir", tracesDir }, { "proxy", proxy }, { "chromiumSandbox", chromiumSandbox }, { "handleSIGINT", handleSIGINT }, { "handleSIGTERM", handleSIGTERM }, { "handleSIGHUP", handleSIGHUP }, { "timeout", timeout }, { "env", env.Remap() }, { "devtools", devtools }, { "slowMo", slowMo }, { "acceptDownloads", acceptDownloads }, { "ignoreHTTPSErrors", ignoreHTTPSErrors }, { "bypassCSP", bypassCSP }, { "strictSelectors", strictSelectors }, }; if (viewportSize?.Width == -1) { channelArgs.Add("noDefaultViewport", true); } else { channelArgs.Add("viewport", viewportSize); } channelArgs.Add("screensize", screenSize); channelArgs.Add("userAgent", userAgent); channelArgs.Add("deviceScaleFactor", deviceScaleFactor); channelArgs.Add("isMobile", isMobile); channelArgs.Add("hasTouch", hasTouch); channelArgs.Add("javaScriptEnabled", javaScriptEnabled); channelArgs.Add("timezoneId", timezoneId); channelArgs.Add("geolocation", geolocation); channelArgs.Add("locale", locale); channelArgs.Add("permissions", permissions); channelArgs.Add("extraHTTPHeaders", extraHTTPHeaders.Remap()); channelArgs.Add("offline", offline); channelArgs.Add("httpCredentials", httpCredentials); channelArgs.Add("colorScheme", colorScheme); channelArgs.Add("reducedMotion", reducedMotion); if (!string.IsNullOrEmpty(recordHarPath)) { channelArgs.Add("recordHar", new { Path = recordHarPath, OmitContent = recordHarOmitContent.GetValueOrDefault(false), }); } if (recordVideo != null) { channelArgs.Add("recordVideo", recordVideo); } channelArgs.Add("ignoreDefaultArgs", ignoreDefaultArgs); channelArgs.Add("ignoreAllDefaultArgs", ignoreAllDefaultArgs); channelArgs.Add("baseURL", baseUrl); channelArgs.Add("forcedColors", forcedColors); return(Connection.SendMessageToServerAsync <BrowserContextChannel>(Guid, "launchPersistentContext", channelArgs)); }