From 37129beac8755c6b25cd5521115732bd457b67a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Sun, 6 Sep 2020 09:53:57 -0300 Subject: [PATCH] API checker (#827) * API checker * dotnet format --- .../LaunchPersistentContextTests.cs | 2 +- .../DownloadsPathLaunchPersistentTests.cs | 2 +- src/PlaywrightSharp.sln | 9 + src/PlaywrightSharp/BrowserType.cs | 8 +- src/PlaywrightSharp/ConsoleMessage.cs | 5 +- src/PlaywrightSharp/Download.cs | 6 +- src/PlaywrightSharp/IBrowserType.cs | 2 +- .../LaunchPersistentOptions.cs | 2 +- src/PlaywrightSharp/ProxySettings.cs | 2 +- src/tools/ApiChecker/ApiChecker.csproj | 20 + src/tools/ApiChecker/PlaywrightArgument.cs | 9 + src/tools/ApiChecker/PlaywrightEntity.cs | 9 + src/tools/ApiChecker/PlaywrightMember.cs | 11 + src/tools/ApiChecker/PlaywrightType.cs | 11 + src/tools/ApiChecker/Program.cs | 269 + src/tools/ApiChecker/api.json | 16620 ++++++++++++++++ 16 files changed, 16971 insertions(+), 16 deletions(-) create mode 100644 src/tools/ApiChecker/ApiChecker.csproj create mode 100644 src/tools/ApiChecker/PlaywrightArgument.cs create mode 100644 src/tools/ApiChecker/PlaywrightEntity.cs create mode 100644 src/tools/ApiChecker/PlaywrightMember.cs create mode 100644 src/tools/ApiChecker/PlaywrightType.cs create mode 100644 src/tools/ApiChecker/Program.cs create mode 100644 src/tools/ApiChecker/api.json diff --git a/src/PlaywrightSharp.Tests/BrowserContext/LaunchPersistentContextTests.cs b/src/PlaywrightSharp.Tests/BrowserContext/LaunchPersistentContextTests.cs index dccbc67dff..214e5a6b0c 100644 --- a/src/PlaywrightSharp.Tests/BrowserContext/LaunchPersistentContextTests.cs +++ b/src/PlaywrightSharp.Tests/BrowserContext/LaunchPersistentContextTests.cs @@ -646,7 +646,7 @@ public async Task ShouldFireCloseEventForAPersistentContext() private async Task<(TempDirectory tmp, IBrowserContext context, IPage page)> LaunchAsync(BrowserContextOptions options = null) { var tmp = new TempDirectory(); - var context = await BrowserType.LaunchPersistenContextAsync( + var context = await BrowserType.LaunchPersistentContextAsync( tmp.Path, TestConstants.GetDefaultBrowserOptions().ToPersistentOptions() + (options ?? new BrowserContextOptions())); var page = context.Pages.First(); diff --git a/src/PlaywrightSharp.Tests/DownloadsPath/DownloadsPathLaunchPersistentTests.cs b/src/PlaywrightSharp.Tests/DownloadsPath/DownloadsPathLaunchPersistentTests.cs index 23a9d74a41..6944bd6116 100644 --- a/src/PlaywrightSharp.Tests/DownloadsPath/DownloadsPathLaunchPersistentTests.cs +++ b/src/PlaywrightSharp.Tests/DownloadsPath/DownloadsPathLaunchPersistentTests.cs @@ -78,7 +78,7 @@ public async Task InitializeAsync() var options = TestConstants.GetDefaultBrowserOptions().ToPersistentOptions(); options.DownloadsPath = _downloadsPath.Path; options.AcceptDownloads = true; - _context = await Playwright[TestConstants.Product].LaunchPersistenContextAsync(_userDataDir.Path, options); + _context = await Playwright[TestConstants.Product].LaunchPersistentContextAsync(_userDataDir.Path, options); _page = _context.Pages[0]; await _page.SetContentAsync($"download"); } diff --git a/src/PlaywrightSharp.sln b/src/PlaywrightSharp.sln index 65bf944448..bca95dadcc 100644 --- a/src/PlaywrightSharp.sln +++ b/src/PlaywrightSharp.sln @@ -22,6 +22,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightSharp", "Playwrig EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightSharp.Demo", "PlaywrightSharp.Demo\PlaywrightSharp.Demo.csproj", "{FB3348E3-9759-4B90-9C8C-391F44AD5F8F}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{5C6D57B1-C82A-48D6-9EBD-73B712CAE476}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiChecker", "tools\ApiChecker\ApiChecker.csproj", "{9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -44,12 +48,17 @@ Global {FB3348E3-9759-4B90-9C8C-391F44AD5F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU {FB3348E3-9759-4B90-9C8C-391F44AD5F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {FB3348E3-9759-4B90-9C8C-391F44AD5F8F}.Release|Any CPU.Build.0 = Release|Any CPU + {9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9430DBAB-C5E3-4D37-84B2-EF86566D5AAA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {A907B324-4541-4FAF-8CAE-D0B512B4BC36} = {D250D790-5A30-4C38-8F60-50FA96DB4E67} + {9430DBAB-C5E3-4D37-84B2-EF86566D5AAA} = {5C6D57B1-C82A-48D6-9EBD-73B712CAE476} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8D6EDE73-B005-4ABC-BCF8-BB3C154497EC} diff --git a/src/PlaywrightSharp/BrowserType.cs b/src/PlaywrightSharp/BrowserType.cs index 9e458c1945..ffec9217f3 100644 --- a/src/PlaywrightSharp/BrowserType.cs +++ b/src/PlaywrightSharp/BrowserType.cs @@ -164,7 +164,7 @@ public Task LaunchPersistenContextAsync( ColorScheme? colorScheme = null, string locale = null, Dictionary extraHttpHeaders = null) - => LaunchPersistenContextAsync( + => LaunchPersistentContextAsync( userAgent, new LaunchPersistentOptions { @@ -233,7 +233,7 @@ public Task LaunchPersistenContextAsync( ColorScheme? colorScheme = null, string locale = null, Dictionary extraHttpHeaders = null) - => LaunchPersistenContextAsync( + => LaunchPersistentContextAsync( userAgent, new LaunchPersistentOptions { @@ -271,10 +271,10 @@ public Task LaunchPersistenContextAsync( /// public Task LaunchPersistenContextAsync(string userDataDir, LaunchOptions options) - => LaunchPersistenContextAsync(userDataDir, options?.ToPersistentOptions() ?? new LaunchPersistentOptions()); + => LaunchPersistentContextAsync(userDataDir, options?.ToPersistentOptions() ?? new LaunchPersistentOptions()); /// - public async Task LaunchPersistenContextAsync(string userDataDir, LaunchPersistentOptions options) + public async Task LaunchPersistentContextAsync(string userDataDir, LaunchPersistentOptions options) => (await _channel.LaunchPersistenContextAsync(userDataDir, options ?? new LaunchPersistentOptions()).ConfigureAwait(false)).Object; /// diff --git a/src/PlaywrightSharp/ConsoleMessage.cs b/src/PlaywrightSharp/ConsoleMessage.cs index 982b22e4dd..9712912d46 100644 --- a/src/PlaywrightSharp/ConsoleMessage.cs +++ b/src/PlaywrightSharp/ConsoleMessage.cs @@ -35,13 +35,11 @@ internal ConsoleMessage(ConnectionScope scope, string guid, ConsoleMessageInitia /// /// Gets the ConsoleMessage type. /// - /// ConsoleMessageType. public string Type => _initializer.Type; /// /// Gets the arguments. /// - /// The arguments. public IEnumerable Args => _initializer.Args.Select(a => ((JSHandleChannel)a).Object); /// @@ -52,7 +50,6 @@ internal ConsoleMessage(ConnectionScope scope, string guid, ConsoleMessageInitia /// /// Gets the console text. /// - /// The text. - internal string Text => _initializer.Text; + public string Text => _initializer.Text; } } diff --git a/src/PlaywrightSharp/Download.cs b/src/PlaywrightSharp/Download.cs index 55230f122d..6844685e47 100644 --- a/src/PlaywrightSharp/Download.cs +++ b/src/PlaywrightSharp/Download.cs @@ -57,19 +57,19 @@ internal Download(ConnectionScope scope, string guid, DownloadInitializer initia /// Returns download error if any. /// /// A that completes when failure is resolved, yielding the faulire. - internal Task GetFailureAsync() => _channel.GetFailureAsync(); + public Task GetFailureAsync() => _channel.GetFailureAsync(); /// /// Deletes the downloaded file. /// /// A that completes when the file is removed. - internal Task DeleteAsync() => _channel.DeleteAsync(); + public Task DeleteAsync() => _channel.DeleteAsync(); /// /// Returns readable stream for current download or null if download failed. /// /// A that completes when the stream is created, yielding the stream. - internal async Task CreateReadStreamAsync() + public async Task CreateReadStreamAsync() { string fileName = await GetPathAsync().ConfigureAwait(false); return string.IsNullOrEmpty(fileName) ? null : new FileStream(fileName, FileMode.Open); diff --git a/src/PlaywrightSharp/IBrowserType.cs b/src/PlaywrightSharp/IBrowserType.cs index 89de7b8507..c852b272b1 100644 --- a/src/PlaywrightSharp/IBrowserType.cs +++ b/src/PlaywrightSharp/IBrowserType.cs @@ -257,7 +257,7 @@ Task LaunchPersistenContextAsync( /// Path to a User Data Directory, which stores browser session data like cookies and local storage. /// Launch options. /// A that completes when the browser is launched, yielding the browser server. - Task LaunchPersistenContextAsync(string userDataDir, LaunchPersistentOptions options); + Task LaunchPersistentContextAsync(string userDataDir, LaunchPersistentOptions options); /// /// This methods attaches PlaywrightSharp to an existing browser instance. diff --git a/src/PlaywrightSharp/LaunchPersistentOptions.cs b/src/PlaywrightSharp/LaunchPersistentOptions.cs index 459f9039e7..01e6fd9151 100644 --- a/src/PlaywrightSharp/LaunchPersistentOptions.cs +++ b/src/PlaywrightSharp/LaunchPersistentOptions.cs @@ -4,7 +4,7 @@ namespace PlaywrightSharp { /// - /// Options for . + /// Options for . /// public class LaunchPersistentOptions : LaunchOptions { diff --git a/src/PlaywrightSharp/ProxySettings.cs b/src/PlaywrightSharp/ProxySettings.cs index 0b97bc46ad..1a4bf44225 100644 --- a/src/PlaywrightSharp/ProxySettings.cs +++ b/src/PlaywrightSharp/ProxySettings.cs @@ -3,7 +3,7 @@ namespace PlaywrightSharp { /// - /// Proxy Settings. See and . + /// Proxy Settings. See and . /// public class ProxySettings { diff --git a/src/tools/ApiChecker/ApiChecker.csproj b/src/tools/ApiChecker/ApiChecker.csproj new file mode 100644 index 0000000000..b5e63f96c2 --- /dev/null +++ b/src/tools/ApiChecker/ApiChecker.csproj @@ -0,0 +1,20 @@ + + + + Exe + netcoreapp3.1 + 0.0.0 + + + + + + + + PreserveNewest + + + + + + diff --git a/src/tools/ApiChecker/PlaywrightArgument.cs b/src/tools/ApiChecker/PlaywrightArgument.cs new file mode 100644 index 0000000000..b6e482dc6e --- /dev/null +++ b/src/tools/ApiChecker/PlaywrightArgument.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace ApiChecker +{ + public class PlaywrightArgument + { + public PlaywrightType Type { get; set; } + } +} diff --git a/src/tools/ApiChecker/PlaywrightEntity.cs b/src/tools/ApiChecker/PlaywrightEntity.cs new file mode 100644 index 0000000000..385b4940da --- /dev/null +++ b/src/tools/ApiChecker/PlaywrightEntity.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace ApiChecker +{ + internal class PlaywrightEntity + { + public Dictionary Members { get; set; } + } +} diff --git a/src/tools/ApiChecker/PlaywrightMember.cs b/src/tools/ApiChecker/PlaywrightMember.cs new file mode 100644 index 0000000000..8a61b7dcc7 --- /dev/null +++ b/src/tools/ApiChecker/PlaywrightMember.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace ApiChecker +{ + public class PlaywrightMember + { + public string Kind { get; set; } + + public Dictionary Args { get; set; } + } +} diff --git a/src/tools/ApiChecker/PlaywrightType.cs b/src/tools/ApiChecker/PlaywrightType.cs new file mode 100644 index 0000000000..e0ee9b0f70 --- /dev/null +++ b/src/tools/ApiChecker/PlaywrightType.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace ApiChecker +{ + public class PlaywrightType + { + public Dictionary Properties { get; set; } + + public string Name { get; set; } + } +} diff --git a/src/tools/ApiChecker/Program.cs b/src/tools/ApiChecker/Program.cs new file mode 100644 index 0000000000..aef2eec1da --- /dev/null +++ b/src/tools/ApiChecker/Program.cs @@ -0,0 +1,269 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.Json; +using PlaywrightSharp; + +namespace ApiChecker +{ + class Program + { + static void Main(string[] args) + { + var report = new StringBuilder("
    "); + string json = File.ReadAllText(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "api.json")); + var api = JsonSerializer.Deserialize>(json, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + }); + + foreach (var kv in api) + { + EvaluateEntity(kv.Key, kv.Value, report); + } + + report.Append("
"); + File.WriteAllText( + Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "report.html"), + report.ToString()); + } + + private static void EvaluateEntity(string name, PlaywrightEntity entity, StringBuilder report) + { + var assembly = Assembly.GetAssembly(typeof(IBrowserType)); + var playwrightSharpEntity = assembly.GetType($"PlaywrightSharp.I{name}"); + + if (playwrightSharpEntity == null) + { + playwrightSharpEntity = assembly.GetType($"PlaywrightSharp.{name}"); + } + + if (playwrightSharpEntity == null) + { + playwrightSharpEntity = assembly.GetType($"PlaywrightSharp.{name}EventArgs"); + } + + if (playwrightSharpEntity != null) + { + report.AppendLine("
  • "); + report.AppendLine($"{name}: found as {playwrightSharpEntity.Name}"); + + report.AppendLine("
      "); + + foreach (var kv in entity.Members) + { + EvaluateMember(kv.Key, kv.Value, entity, playwrightSharpEntity, report); + } + + report.AppendLine("
    "); + report.AppendLine("
  • "); + + } + else + { + report.AppendLine("
  • "); + report.AppendLine($"{name} NOT FOUND"); + report.AppendLine("
  • "); + } + } + + private static void EvaluateMember(string memberName, PlaywrightMember member, PlaywrightEntity entity, Type playwrightSharpEntity, StringBuilder report) + { + switch (member.Kind) + { + case "event": + EvaluateEvent(memberName, member, entity, playwrightSharpEntity, report); + return; + case "method": + EvaluateMethod(memberName, member, playwrightSharpEntity, report); + return; + } + } + + private static void EvaluateMethod(string memberName, PlaywrightMember member, Type playwrightSharpEntity, StringBuilder report) + { + memberName = TranslateMethodName(memberName); + var typeToCheck = playwrightSharpEntity; + MethodInfo playwrightSharpMethod = null; + + while (typeToCheck != null && playwrightSharpMethod == null) + { + playwrightSharpMethod = typeToCheck.GetMethods().FirstOrDefault(m => m.Name.ToLower() == memberName.ToLower()); + + if (playwrightSharpMethod == null) + { + playwrightSharpMethod = typeToCheck.GetMethods().FirstOrDefault(m => m.Name.ToLower() == memberName.ToLower() + "async"); + } + + if (playwrightSharpMethod == null) + { + playwrightSharpMethod = typeToCheck.GetMethods().FirstOrDefault(m => m.Name.ToLower() == $"get{memberName.ToLower()}async"); + } + + if (playwrightSharpMethod == null) + { + playwrightSharpMethod = typeToCheck.GetMethods().FirstOrDefault(m => m.Name.ToLower() == $"get{memberName.ToLower()}"); + } + + typeToCheck = typeToCheck.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(); + } + + if (playwrightSharpMethod != null) + { + report.AppendLine("
  • "); + report.AppendLine($"{memberName}: found as {playwrightSharpMethod.Name}"); + + report.AppendLine("
      "); + + if (member.Args != null) + { + int position = 0; + + foreach (var kv in member.Args) + { + // we flatten options + if (kv.Key == "options") + { + + foreach (var arg in kv.Value.Type.Properties) + { + EvaluateArgument(arg.Key, arg.Value, playwrightSharpMethod, report, position); + position++; + } + } + else + { + EvaluateArgument(kv.Key, kv.Value, playwrightSharpMethod, report, position); + position++; + } + } + } + + report.AppendLine("
    "); + report.AppendLine("
  • "); + + } + else + { + var playwrightSharpProperty = playwrightSharpEntity.GetProperties().FirstOrDefault(p => p.Name.ToLower() == memberName.ToLower()); + + if (playwrightSharpProperty != null) + { + report.AppendLine("
  • "); + report.AppendLine($"{memberName}: found as as Property {playwrightSharpProperty.Name}"); + report.AppendLine("
  • "); + } + else + { + report.AppendLine("
  • "); + report.AppendLine($"{memberName} NOT FOUND"); + report.AppendLine("
  • "); + } + } + } + + private static string TranslateMethodName(string memberName) + { + return memberName + .Replace("$$eval", "evalOnSelectorAll") + .Replace("$eval", "evalOnSelector") + .Replace("$$", "querySelectorAll") + .Replace("$", "querySelector"); + } + + private static void EvaluateArgument(string name, PlaywrightArgument arg, MethodInfo playwrightSharpMethod, StringBuilder report, int position) + { + var playwrightSharpArgument = playwrightSharpMethod.GetParameters().FirstOrDefault(p => p.Name.ToLower() == name.ToLower()); + + if (playwrightSharpArgument != null) + { + if (!IsSameType(playwrightSharpArgument.ParameterType, arg.Type.Name)) + { + report.AppendLine("
  • "); + report.AppendLine($"{name} ({arg.Type.Name.Replace("<", "{").Replace(">", "}")}): found as {playwrightSharpArgument.Name} but with type {playwrightSharpArgument.ParameterType}"); + } + else + { + report.AppendLine("
  • "); + report.AppendLine($"{name} ({arg.Type.Name}): found as {playwrightSharpArgument.Name} ({playwrightSharpArgument.ParameterType})"); + } + + if (arg.Type.Name.Contains("Object")) + { + report.AppendLine("
      "); + + foreach (var kv in arg.Type.Properties) + { + EvaluateProperty(kv.Key, kv.Value, playwrightSharpArgument.ParameterType, report); + } + + report.AppendLine("
    "); + } + + report.AppendLine("
  • "); + } + } + + private static bool IsSameType(Type parameterType, string plywrightType) + { + if (plywrightType.Contains("Array<")) + { + plywrightType = plywrightType.Replace("Array<", "").Replace(">", ""); + return parameterType.Name.ToLower() == plywrightType; + } + + return plywrightType.Replace("null|", string.Empty) switch + { + "string" => parameterType == typeof(string), + "number" => parameterType == typeof(int) || parameterType == typeof(decimal) || parameterType == typeof(int?) || parameterType == typeof(decimal?), + "Array" => parameterType == typeof(Array) && parameterType.GenericTypeArguments[0] == typeof(string), + "boolean" => parameterType == typeof(bool) || parameterType == typeof(Nullable), + "Object" => parameterType == typeof(Dictionary), + "Object" => true, + _ => false, + }; + } + + private static void EvaluateProperty(string memberName, PlaywrightArgument arg, Type playwrightSharpType, StringBuilder report) + { + var playwrightSharpProperty = playwrightSharpType.GetProperties().FirstOrDefault(p => p.Name.ToLower() == memberName.ToLower()); + + if (playwrightSharpProperty != null) + { + if (!IsSameType(playwrightSharpProperty.PropertyType, arg.Type.Name)) + { + report.AppendLine("
  • "); + } + else + { + report.AppendLine("
  • "); + } + + report.AppendLine($"{memberName} ({arg.Type.Name}): found as as Property {playwrightSharpProperty.Name} with type ({playwrightSharpProperty.PropertyType})"); + report.AppendLine("
  • "); + } + } + + private static void EvaluateEvent(string memberName, PlaywrightMember member, PlaywrightEntity entity, Type playwrightSharpEntity, StringBuilder report) + { + var playwrightSharpEvent = playwrightSharpEntity.GetEvents().FirstOrDefault(e => e.Name.ToLower() == memberName.ToLower()); + + if (playwrightSharpEvent != null) + { + report.AppendLine("
  • "); + report.AppendLine($"{memberName}: found as {playwrightSharpEvent.Name}"); + report.AppendLine("
  • "); + } + else + { + report.AppendLine("
  • "); + report.AppendLine($"{memberName} NOT FOUND"); + report.AppendLine("
  • "); + } + } + } +} diff --git a/src/tools/ApiChecker/api.json b/src/tools/ApiChecker/api.json new file mode 100644 index 0000000000..a64ceed875 --- /dev/null +++ b/src/tools/ApiChecker/api.json @@ -0,0 +1,16620 @@ +{ + "Browser": { + "name": "Browser", + "members": { + "disconnected": { + "kind": "event", + "name": "disconnected", + "type": null, + "comment": "", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "close": { + "kind": "method", + "name": "close", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "In case this browser is obtained using browserType.launch, closes the browser and all of its pages (if any were opened).\nIn case this browser is obtained using browserType.connect, clears all created contexts belonging to this browser and disconnects from the browser server.\nThe Browser object itself is considered to be disposed and cannot be used anymore.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "contexts": { + "kind": "method", + "name": "contexts", + "type": { + "name": "Array", + "properties": {} + }, + "comment": "Returns an array of all open browser contexts. In a newly created browser, this will return zero\nbrowser contexts.\n```js\nconst browser = await pw.webkit.launch();\nconsole.log(browser.contexts().length); // prints `0`\n\nconst context = await browser.newContext();\nconsole.log(browser.contexts().length); // prints `1`\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "isConnected": { + "kind": "method", + "name": "isConnected", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Indicates that the browser is connected.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "newContext": { + "kind": "method", + "name": "newContext", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Creates a new browser context. It won't share cookies/cache with other browser contexts.\n```js\n(async () => {\n const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.\n // Create a new incognito browser context.\n const context = await browser.newContext();\n // Create a new page in a pristine context.\n const page = await context.newPage();\n await page.goto('https://example.com');\n})();\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "options": { + "kind": "property", + "name": "options", + "type": { + "name": "Object", + "properties": { + "acceptDownloads": { + "kind": "property", + "name": "acceptDownloads", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.", + "returnComment": "", + "required": false, + "templates": [] + }, + "ignoreHTTPSErrors": { + "kind": "property", + "name": "ignoreHTTPSErrors", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to ignore HTTPS errors during navigation. Defaults to `false`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "bypassCSP": { + "kind": "property", + "name": "bypassCSP", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Toggles bypassing page's Content-Security-Policy.", + "returnComment": "", + "required": false, + "templates": [] + }, + "viewport": { + "kind": "property", + "name": "viewport", + "type": { + "name": "null|Object", + "properties": { + "width": { + "kind": "property", + "name": "width", + "type": { + "name": "number", + "properties": {} + }, + "comment": "page width in pixels.", + "returnComment": "", + "required": true, + "templates": [] + }, + "height": { + "kind": "property", + "name": "height", + "type": { + "name": "number", + "properties": {} + }, + "comment": "page height in pixels.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "comment": "Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.", + "returnComment": "", + "required": false, + "templates": [] + }, + "userAgent": { + "kind": "property", + "name": "userAgent", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Specific user agent to use in this context.", + "returnComment": "", + "required": false, + "templates": [] + }, + "deviceScaleFactor": { + "kind": "property", + "name": "deviceScaleFactor", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Specify device scale factor (can be thought of as dpr). Defaults to `1`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "isMobile": { + "kind": "property", + "name": "isMobile", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox.", + "returnComment": "", + "required": false, + "templates": [] + }, + "hasTouch": { + "kind": "property", + "name": "hasTouch", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Specifies if viewport supports touch events. Defaults to false.", + "returnComment": "", + "required": false, + "templates": [] + }, + "javaScriptEnabled": { + "kind": "property", + "name": "javaScriptEnabled", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether or not to enable JavaScript in the context. Defaults to true.", + "returnComment": "", + "required": false, + "templates": [] + }, + "timezoneId": { + "kind": "property", + "name": "timezoneId", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Changes the timezone of the context. See ICU’s `metaZones.txt` for a list of supported timezone IDs.", + "returnComment": "", + "required": false, + "templates": [] + }, + "geolocation": { + "kind": "property", + "name": "geolocation", + "type": { + "name": "Object", + "properties": { + "latitude": { + "kind": "property", + "name": "latitude", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Latitude between -90 and 90.", + "returnComment": "", + "required": true, + "templates": [] + }, + "longitude": { + "kind": "property", + "name": "longitude", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Longitude between -180 and 180.", + "returnComment": "", + "required": true, + "templates": [] + }, + "accuracy": { + "kind": "property", + "name": "accuracy", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Non-negative accuracy value. Defaults to `0`.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + }, + "locale": { + "kind": "property", + "name": "locale", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.", + "returnComment": "", + "required": false, + "templates": [] + }, + "permissions": { + "kind": "property", + "name": "permissions", + "type": { + "name": "Array", + "properties": {} + }, + "comment": "A list of permissions to grant to all pages in this context. See browserContext.grantPermissions for more details.", + "returnComment": "", + "required": false, + "templates": [] + }, + "extraHTTPHeaders": { + "kind": "property", + "name": "extraHTTPHeaders", + "type": { + "name": "Object", + "properties": {} + }, + "comment": "An object containing additional HTTP headers to be sent with every request. All header values must be strings.", + "returnComment": "", + "required": false, + "templates": [] + }, + "offline": { + "kind": "property", + "name": "offline", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to emulate network being offline. Defaults to `false`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "httpCredentials": { + "kind": "property", + "name": "httpCredentials", + "type": { + "name": "Object", + "properties": { + "username": { + "kind": "property", + "name": "username", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "password": { + "kind": "property", + "name": "password", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "comment": "Credentials for HTTP authentication.", + "returnComment": "", + "required": false, + "templates": [] + }, + "colorScheme": { + "kind": "property", + "name": "colorScheme", + "type": { + "name": "\"dark\"|\"light\"|\"no-preference\"", + "properties": {} + }, + "comment": "Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'.", + "returnComment": "", + "required": false, + "templates": [] + }, + "logger": { + "kind": "property", + "name": "logger", + "type": { + "name": "Logger", + "properties": {} + }, + "comment": "Logger sink for Playwright logging.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "newPage": { + "kind": "method", + "name": "newPage", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Creates a new page in a new browser context. Closing this page will close the context as well.\nThis is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and testing frameworks should explicitly create browser.newContext followed by the browserContext.newPage to control their exact life times.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "options": { + "kind": "property", + "name": "options", + "type": { + "name": "Object", + "properties": { + "acceptDownloads": { + "kind": "property", + "name": "acceptDownloads", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.", + "returnComment": "", + "required": false, + "templates": [] + }, + "ignoreHTTPSErrors": { + "kind": "property", + "name": "ignoreHTTPSErrors", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to ignore HTTPS errors during navigation. Defaults to `false`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "bypassCSP": { + "kind": "property", + "name": "bypassCSP", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Toggles bypassing page's Content-Security-Policy.", + "returnComment": "", + "required": false, + "templates": [] + }, + "viewport": { + "kind": "property", + "name": "viewport", + "type": { + "name": "null|Object", + "properties": { + "width": { + "kind": "property", + "name": "width", + "type": { + "name": "number", + "properties": {} + }, + "comment": "page width in pixels.", + "returnComment": "", + "required": true, + "templates": [] + }, + "height": { + "kind": "property", + "name": "height", + "type": { + "name": "number", + "properties": {} + }, + "comment": "page height in pixels.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "comment": "Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.", + "returnComment": "", + "required": false, + "templates": [] + }, + "userAgent": { + "kind": "property", + "name": "userAgent", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Specific user agent to use in this context.", + "returnComment": "", + "required": false, + "templates": [] + }, + "deviceScaleFactor": { + "kind": "property", + "name": "deviceScaleFactor", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Specify device scale factor (can be thought of as dpr). Defaults to `1`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "isMobile": { + "kind": "property", + "name": "isMobile", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox.", + "returnComment": "", + "required": false, + "templates": [] + }, + "hasTouch": { + "kind": "property", + "name": "hasTouch", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Specifies if viewport supports touch events. Defaults to false.", + "returnComment": "", + "required": false, + "templates": [] + }, + "javaScriptEnabled": { + "kind": "property", + "name": "javaScriptEnabled", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether or not to enable JavaScript in the context. Defaults to `true`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "timezoneId": { + "kind": "property", + "name": "timezoneId", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Changes the timezone of the context. See ICU’s `metaZones.txt` for a list of supported timezone IDs.", + "returnComment": "", + "required": false, + "templates": [] + }, + "geolocation": { + "kind": "property", + "name": "geolocation", + "type": { + "name": "Object", + "properties": { + "latitude": { + "kind": "property", + "name": "latitude", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Latitude between -90 and 90.", + "returnComment": "", + "required": true, + "templates": [] + }, + "longitude": { + "kind": "property", + "name": "longitude", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Longitude between -180 and 180.", + "returnComment": "", + "required": true, + "templates": [] + }, + "accuracy": { + "kind": "property", + "name": "accuracy", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Non-negative accuracy value. Defaults to `0`.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + }, + "locale": { + "kind": "property", + "name": "locale", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules.", + "returnComment": "", + "required": false, + "templates": [] + }, + "permissions": { + "kind": "property", + "name": "permissions", + "type": { + "name": "Array", + "properties": {} + }, + "comment": "A list of permissions to grant to all pages in this context. See browserContext.grantPermissions for more details.", + "returnComment": "", + "required": false, + "templates": [] + }, + "extraHTTPHeaders": { + "kind": "property", + "name": "extraHTTPHeaders", + "type": { + "name": "Object", + "properties": {} + }, + "comment": "An object containing additional HTTP headers to be sent with every request. All header values must be strings.", + "returnComment": "", + "required": false, + "templates": [] + }, + "offline": { + "kind": "property", + "name": "offline", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to emulate network being offline. Defaults to `false`.", + "returnComment": "", + "required": false, + "templates": [] + }, + "httpCredentials": { + "kind": "property", + "name": "httpCredentials", + "type": { + "name": "Object", + "properties": { + "username": { + "kind": "property", + "name": "username", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "password": { + "kind": "property", + "name": "password", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "comment": "Credentials for HTTP authentication.", + "returnComment": "", + "required": false, + "templates": [] + }, + "colorScheme": { + "kind": "property", + "name": "colorScheme", + "type": { + "name": "\"dark\"|\"light\"|\"no-preference\"", + "properties": {} + }, + "comment": "Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See page.emulateMedia(options) for more details. Defaults to '`light`'.", + "returnComment": "", + "required": false, + "templates": [] + }, + "logger": { + "kind": "property", + "name": "logger", + "type": { + "name": "Logger", + "properties": {} + }, + "comment": "Logger sink for Playwright logging.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "version": { + "kind": "method", + "name": "version", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Returns the browser version.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + } + } + }, + "BrowserContext": { + "name": "BrowserContext", + "members": { + "close": { + "kind": "method", + "name": "close", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Closes the browser context. All the pages that belong to the browser context\nwill be closed.\n\n**NOTE** the default browser context cannot be closed.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "page": { + "kind": "event", + "name": "page", + "type": { + "name": "Page", + "properties": {} + }, + "comment": "The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will also fire for popup pages. See also `Page.on('popup')` to receive events about popups relevant to a specific page.\nThe earliest moment that page is available is when it has navigated to the initial url. For example, when opening a popup with `window.open('http://example.com')`, this event will fire when the network request to \"http://example.com\" is done and its response has started loading in the popup.\n```js\nconst [page] = await Promise.all([\n context.waitForEvent('page'),\n page.click('a[target=_blank]'),\n]);\nconsole.log(await page.evaluate('location.href'));\n```\n\n**NOTE** Use `page.waitForLoadState([state[, options]])` to wait until the page gets to a particular state (you should not need it in most cases).", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "addCookies": { + "kind": "method", + "name": "addCookies", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "```js\nawait browserContext.addCookies([cookieObject1, cookieObject2]);\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "cookies": { + "kind": "property", + "name": "cookies", + "type": { + "name": "Array", + "properties": { + "name": { + "kind": "property", + "name": "name", + "type": { + "name": "string", + "properties": {} + }, + "comment": "**required**", + "returnComment": "", + "required": true, + "templates": [] + }, + "value": { + "kind": "property", + "name": "value", + "type": { + "name": "string", + "properties": {} + }, + "comment": "**required**", + "returnComment": "", + "required": true, + "templates": [] + }, + "url": { + "kind": "property", + "name": "url", + "type": { + "name": "string", + "properties": {} + }, + "comment": "either url or domain / path are required", + "returnComment": "", + "required": false, + "templates": [] + }, + "domain": { + "kind": "property", + "name": "domain", + "type": { + "name": "string", + "properties": {} + }, + "comment": "either url or domain / path are required", + "returnComment": "", + "required": false, + "templates": [] + }, + "path": { + "kind": "property", + "name": "path", + "type": { + "name": "string", + "properties": {} + }, + "comment": "either url or domain / path are required", + "returnComment": "", + "required": false, + "templates": [] + }, + "expires": { + "kind": "property", + "name": "expires", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Unix time in seconds.", + "returnComment": "", + "required": false, + "templates": [] + }, + "httpOnly": { + "kind": "property", + "name": "httpOnly", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + }, + "secure": { + "kind": "property", + "name": "secure", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + }, + "sameSite": { + "kind": "property", + "name": "sameSite", + "type": { + "name": "\"Lax\"|\"None\"|\"Strict\"", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "addInitScript": { + "kind": "method", + "name": "addInitScript", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Adds a script which would be evaluated in one of the following scenarios:\n\nWhenever a page is created in the browser context or is navigated.\nWhenever a child frame is attached or navigated in any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame.\n\nThe script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`.\nAn example of overriding `Math.random` before the page loads:\n```js\n// preload.js\nMath.random = () => 42;\n```\n```js\n// In your playwright script, assuming the preload.js file is in same folder.\nawait browserContext.addInitScript({\n path: 'preload.js'\n});\n```\n\n**NOTE** The order of evaluation of multiple scripts installed via browserContext.addInitScript(script[, arg]) and page.addInitScript(script[, arg]) is not defined.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "script": { + "kind": "property", + "name": "script", + "type": { + "name": "function|string|Object", + "properties": { + "path": { + "kind": "property", + "name": "path", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to current working directory.", + "returnComment": "", + "required": false, + "templates": [] + }, + "content": { + "kind": "property", + "name": "content", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Raw script content.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "Script to be evaluated in all pages in the browser context.", + "returnComment": "", + "required": true, + "templates": [] + }, + "arg": { + "kind": "property", + "name": "arg", + "type": { + "name": "Serializable", + "properties": {} + }, + "comment": "Optional argument to pass to `script` (only supported when passing a function).", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "clearCookies": { + "kind": "method", + "name": "clearCookies", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Clears context cookies.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "clearPermissions": { + "kind": "method", + "name": "clearPermissions", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Clears all permission overrides for the browser context.\n```js\nconst context = await browser.newContext();\nawait context.grantPermissions(['clipboard-read']);\n// do stuff ..\ncontext.clearPermissions();\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "cookies": { + "kind": "method", + "name": "cookies", + "type": { + "name": "Promise>", + "properties": { + "name": { + "kind": "property", + "name": "name", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "value": { + "kind": "property", + "name": "value", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "domain": { + "kind": "property", + "name": "domain", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "path": { + "kind": "property", + "name": "path", + "type": { + "name": "string", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "expires": { + "kind": "property", + "name": "expires", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Unix time in seconds.", + "returnComment": "", + "required": true, + "templates": [] + }, + "httpOnly": { + "kind": "property", + "name": "httpOnly", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "secure": { + "kind": "property", + "name": "secure", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + }, + "sameSite": { + "kind": "property", + "name": "sameSite", + "type": { + "name": "\"Lax\"|\"None\"|\"Strict\"", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "comment": "If no URLs are specified, this method returns all cookies.\nIf URLs are specified, only cookies that affect those URLs are returned.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "urls": { + "kind": "property", + "name": "urls", + "type": { + "name": "string|Array", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "exposeBinding": { + "kind": "method", + "name": "exposeBinding", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The method adds a function called `name` on the `window` object of every frame in every page in the context.\nWhen called, the function executes `playwrightBinding` in Node.js and returns a Promise which resolves to the return value of `playwrightBinding`.\nIf the `playwrightBinding` returns a Promise, it will be awaited.\nThe first argument of the `playwrightBinding` function contains information about the caller:\n`{ browserContext: BrowserContext, page: Page, frame: Frame }`.\nSee page.exposeBinding(name, playwrightBinding) for page-only version.\nAn example of exposing page URL to all frames in all pages in the context:\n```js\nconst { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.\n\n(async () => {\n const browser = await webkit.launch({ headless: false });\n const context = await browser.newContext();\n await context.exposeBinding('pageURL', ({ page }) => page.url());\n const page = await context.newPage();\n await page.setContent(`\n \n \n
    \n `);\n await page.click('button');\n})();\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "name": { + "kind": "property", + "name": "name", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Name of the function on the window object.", + "returnComment": "", + "required": true, + "templates": [] + }, + "playwrightBinding": { + "kind": "property", + "name": "playwrightBinding", + "type": { + "name": "function", + "properties": {} + }, + "comment": "Callback function that will be called in the Playwright's context.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "exposeFunction": { + "kind": "method", + "name": "exposeFunction", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The method adds a function called `name` on the `window` object of every frame in every page in the context.\nWhen called, the function executes `playwrightFunction` in Node.js and returns a Promise which resolves to the return value of `playwrightFunction`.\nIf the `playwrightFunction` returns a Promise, it will be awaited.\nSee page.exposeFunction(name, playwrightFunction) for page-only version.\nAn example of adding an `md5` function to all pages in the context:\n```js\nconst { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.\nconst crypto = require('crypto');\n\n(async () => {\n const browser = await webkit.launch({ headless: false });\n const context = await browser.newContext();\n await context.exposeFunction('md5', text => crypto.createHash('md5').update(text).digest('hex'));\n const page = await context.newPage();\n await page.setContent(`\n \n \n
    \n `);\n await page.click('button');\n})();\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "name": { + "kind": "property", + "name": "name", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Name of the function on the window object.", + "returnComment": "", + "required": true, + "templates": [] + }, + "playwrightFunction": { + "kind": "property", + "name": "playwrightFunction", + "type": { + "name": "function", + "properties": {} + }, + "comment": "Callback function that will be called in the Playwright's context.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "grantPermissions": { + "kind": "method", + "name": "grantPermissions", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if specified.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "permissions": { + "kind": "property", + "name": "permissions", + "type": { + "name": "Array", + "properties": {} + }, + "comment": "A permission or an array of permissions to grant. Permissions can be one of the following values:\n - `'*'`\n - `'geolocation'`\n - `'midi'`\n - `'midi-sysex'` (system-exclusive midi)\n - `'notifications'`\n - `'push'`\n - `'camera'`\n - `'microphone'`\n - `'background-sync'`\n - `'ambient-light-sensor'`\n - `'accelerometer'`\n - `'gyroscope'`\n - `'magnetometer'`\n - `'accessibility-events'`\n - `'clipboard-read'`\n - `'clipboard-write'`\n - `'payment-handler'`", + "returnComment": "", + "required": true, + "templates": [] + }, + "options": { + "kind": "property", + "name": "options", + "type": { + "name": "Object", + "properties": { + "origin": { + "kind": "property", + "name": "origin", + "type": { + "name": "string", + "properties": {} + }, + "comment": "The origin to grant permissions to, e.g. \"https://example.com\".", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "newPage": { + "kind": "method", + "name": "newPage", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Creates a new page in the browser context.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "pages": { + "kind": "method", + "name": "pages", + "type": { + "name": "Array", + "properties": {} + }, + "comment": "", + "returnComment": "All open pages in the context. Non visible pages, such as `\"background_page\"`, will not be listed here. You can find them using chromiumBrowserContext.backgroundPages().", + "required": true, + "templates": [], + "args": {} + }, + "route": { + "kind": "method", + "name": "route", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Routing provides the capability to modify network requests that are made by any page in the browser context.\nOnce route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.\nAn example of a naïve handler that aborts all image requests:\n```js\nconst context = await browser.newContext();\nawait context.route('**/*.{png,jpg,jpeg}', route => route.abort());\nconst page = await context.newPage();\nawait page.goto('https://example.com');\nawait browser.close();\n```\nor the same snippet using a regex pattern instead:\n```js\nconst context = await browser.newContext();\nawait context.route(/(\\.png$)|(\\.jpg$)/, route => route.abort());\nconst page = await context.newPage();\nawait page.goto('https://example.com');\nawait browser.close();\n```\nPage routes (set up with page.route(url, handler)) take precedence over browser context routes when request matches both handlers.\n\n**NOTE** Enabling routing disables http cache.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "url": { + "kind": "property", + "name": "url", + "type": { + "name": "string|RegExp|function(URL):boolean", + "properties": {} + }, + "comment": "A glob pattern, regex pattern or predicate receiving URL to match while routing.", + "returnComment": "", + "required": true, + "templates": [] + }, + "handler": { + "kind": "property", + "name": "handler", + "type": { + "name": "function(Route, Request)", + "properties": {} + }, + "comment": "handler function to route the request.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "setDefaultNavigationTimeout": { + "kind": "method", + "name": "setDefaultNavigationTimeout", + "type": null, + "comment": "This setting will change the default maximum navigation time for the following methods and related shortcuts:\n\npage.goBack([options])\npage.goForward([options])\npage.goto(url[, options])\npage.reload([options])\npage.setContent(html[, options])\npage.waitForNavigation([options])\n\n\n**NOTE** `page.setDefaultNavigationTimeout` and `page.setDefaultTimeout` take priority over `browserContext.setDefaultNavigationTimeout`.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "timeout": { + "kind": "property", + "name": "timeout", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Maximum navigation time in milliseconds", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "setDefaultTimeout": { + "kind": "method", + "name": "setDefaultTimeout", + "type": null, + "comment": "This setting will change the default maximum time for all the methods accepting `timeout` option.\n\n**NOTE** `page.setDefaultNavigationTimeout`, `page.setDefaultTimeout` and `browserContext.setDefaultNavigationTimeout` take priority over `browserContext.setDefaultTimeout`.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "timeout": { + "kind": "property", + "name": "timeout", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Maximum time in milliseconds", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "setExtraHTTPHeaders": { + "kind": "method", + "name": "setExtraHTTPHeaders", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged with page-specific extra HTTP headers set with page.setExtraHTTPHeaders(). If page overrides a particular header, page-specific header value will be used instead of the browser context header value.\n\n**NOTE** `browserContext.setExtraHTTPHeaders` does not guarantee the order of headers in the outgoing requests.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "headers": { + "kind": "property", + "name": "headers", + "type": { + "name": "Object", + "properties": {} + }, + "comment": "An object containing additional HTTP headers to be sent with every request. All header values must be strings.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "setGeolocation": { + "kind": "method", + "name": "setGeolocation", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.\n```js\nawait browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});\n```\n\n**NOTE** Consider using browserContext.grantPermissions to grant permissions for the browser context pages to read its geolocation.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "geolocation": { + "kind": "property", + "name": "geolocation", + "type": { + "name": "null|Object", + "properties": { + "latitude": { + "kind": "property", + "name": "latitude", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Latitude between -90 and 90. **required**", + "returnComment": "", + "required": true, + "templates": [] + }, + "longitude": { + "kind": "property", + "name": "longitude", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Longitude between -180 and 180. **required**", + "returnComment": "", + "required": true, + "templates": [] + }, + "accuracy": { + "kind": "property", + "name": "accuracy", + "type": { + "name": "number", + "properties": {} + }, + "comment": "Non-negative accuracy value. Defaults to `0`.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "setHTTPCredentials": { + "kind": "method", + "name": "setHTTPCredentials", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Provide credentials for HTTP authentication.\n\n**NOTE** Browsers may cache credentials after successful authentication. Passing different credentials or passing `null` to disable authentication will be unreliable. To remove or replace credentials, create a new browser context instead.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "httpCredentials": { + "kind": "property", + "name": "httpCredentials", + "type": { + "name": "null|Object", + "properties": { + "username": { + "kind": "property", + "name": "username", + "type": { + "name": "string", + "properties": {} + }, + "comment": "**required**", + "returnComment": "", + "required": true, + "templates": [] + }, + "password": { + "kind": "property", + "name": "password", + "type": { + "name": "string", + "properties": {} + }, + "comment": "**required**", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "setOffline": { + "kind": "method", + "name": "setOffline", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "offline": { + "kind": "property", + "name": "offline", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Whether to emulate network being offline for the browser context.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "unroute": { + "kind": "method", + "name": "unroute", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Removes a route created with browserContext.route(url, handler). When `handler` is not specified, removes all routes for the `url`.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "url": { + "kind": "property", + "name": "url", + "type": { + "name": "string|RegExp|function(URL):boolean", + "properties": {} + }, + "comment": "A glob pattern, regex pattern or predicate receiving URL used to register a routing with browserContext.route(url, handler).", + "returnComment": "", + "required": true, + "templates": [] + }, + "handler": { + "kind": "property", + "name": "handler", + "type": { + "name": "function(Route, Request)", + "properties": {} + }, + "comment": "Handler function used to register a routing with browserContext.route(url, handler).", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "waitForEvent": { + "kind": "method", + "name": "waitForEvent", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Waits for event to fire and passes its value into the predicate function. Resolves when the predicate returns truthy value. Will throw an error if the context closes before the event\nis fired.\n```js\nconst context = await browser.newContext();\nawait context.grantPermissions(['geolocation']);\n```", + "returnComment": "Promise which resolves to the event data value.", + "required": true, + "templates": [], + "args": { + "event": { + "kind": "property", + "name": "event", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Event name, same one would pass into `browserContext.on(event)`.", + "returnComment": "", + "required": true, + "templates": [] + }, + "optionsOrPredicate": { + "kind": "property", + "name": "optionsOrPredicate", + "type": { + "name": "Function|Object", + "properties": { + "predicate": { + "kind": "property", + "name": "predicate", + "type": { + "name": "Function", + "properties": {} + }, + "comment": "receives the event data and resolves to truthy value when the waiting should resolve.", + "returnComment": "", + "required": false, + "templates": [] + }, + "timeout": { + "kind": "property", + "name": "timeout", + "type": { + "name": "number", + "properties": {} + }, + "comment": "maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout).", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "Either a predicate that receives an event or an options object.", + "returnComment": "", + "required": false, + "templates": [] + } + } + } + } + }, + "Page": { + "name": "Page", + "members": { + "close": { + "kind": "method", + "name": "close", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "By default, `page.close()` **does not** run beforeunload handlers.\n\n**NOTE** if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned\nand should be handled manually via page's 'dialog' event.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "options": { + "kind": "property", + "name": "options", + "type": { + "name": "Object", + "properties": { + "runBeforeUnload": { + "kind": "property", + "name": "runBeforeUnload", + "type": { + "name": "boolean", + "properties": {} + }, + "comment": "Defaults to `false`. Whether to run the\nbefore unload\npage handlers.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "console": { + "kind": "event", + "name": "console", + "type": { + "name": "ConsoleMessage", + "properties": {} + }, + "comment": "Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also emitted if the page throws an error or a warning.\nThe arguments passed into `console.log` appear as arguments on the event handler.\nAn example of handling `console` event:\n```js\npage.on('console', msg => {\n for (let i = 0; i < msg.args().length; ++i)\n console.log(`${i}: ${msg.args()[i]}`);\n});\npage.evaluate(() => console.log('hello', 5, {foo: 'bar'}));\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "crash": { + "kind": "event", + "name": "crash", + "type": null, + "comment": "Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes, ongoing and subsequent operations will throw.\nThe most common way to deal with crashes is to catch an exception:\n```js\ntry {\n // Crash might happen during a click.\n await page.click('button');\n // Or while waiting for an event.\n await page.waitForEvent('popup');\n} catch (e) {\n // When the page crashes, exception message contains 'crash'.\n}\n```\nHowever, when manually listening to events, it might be useful to avoid stalling when the page crashes. In this case, handling `crash` event helps:\n```js\nawait new Promise((resolve, reject) => {\n page.on('requestfinished', async request => {\n if (await someProcessing(request))\n resolve(request);\n });\n page.on('crash', error => reject(error));\n});\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "dialog": { + "kind": "event", + "name": "dialog", + "type": { + "name": "Dialog", + "properties": {} + }, + "comment": "Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Playwright can respond to the dialog via Dialog's accept or dismiss methods.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "domcontentloaded": { + "kind": "event", + "name": "domcontentloaded", + "type": null, + "comment": "Emitted when the JavaScript `DOMContentLoaded` event is dispatched.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "download": { + "kind": "event", + "name": "download", + "type": { + "name": "Download", + "properties": {} + }, + "comment": "Emitted when attachment download started. User can access basic file operations on downloaded content via the passed Download instance.\n\n**NOTE** Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the downloaded content. If `acceptDownloads` is not set or set to `false`, download events are emitted, but the actual download is not performed and user has no access to the downloaded files.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "filechooser": { + "kind": "event", + "name": "filechooser", + "type": { + "name": "FileChooser", + "properties": {} + }, + "comment": "Emitted when a file chooser is supposed to appear, such as after clicking the ``. Playwright can respond to it via setting the input files using `fileChooser.setFiles` that can be uploaded after that.\n```js\npage.on('filechooser', async (fileChooser) => {\n await fileChooser.setFiles('/tmp/myfile.pdf');\n});\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "frameattached": { + "kind": "event", + "name": "frameattached", + "type": { + "name": "Frame", + "properties": {} + }, + "comment": "Emitted when a frame is attached.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "framedetached": { + "kind": "event", + "name": "framedetached", + "type": { + "name": "Frame", + "properties": {} + }, + "comment": "Emitted when a frame is detached.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "framenavigated": { + "kind": "event", + "name": "framenavigated", + "type": { + "name": "Frame", + "properties": {} + }, + "comment": "Emitted when a frame is navigated to a new url.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "load": { + "kind": "event", + "name": "load", + "type": null, + "comment": "Emitted when the JavaScript `load` event is dispatched.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "pageerror": { + "kind": "event", + "name": "pageerror", + "type": { + "name": "Error", + "properties": {} + }, + "comment": "Emitted when an uncaught exception happens within the page.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "popup": { + "kind": "event", + "name": "popup", + "type": { + "name": "Page", + "properties": {} + }, + "comment": "Emitted when the page opens a new tab or window. This event is emitted in addition to the `browserContext.on('page')`, but only for popups relevant to this page.\nThe earliest moment that page is available is when it has navigated to the initial url. For example, when opening a popup with `window.open('http://example.com')`, this event will fire when the network request to \"http://example.com\" is done and its response has started loading in the popup.\n```js\nconst [popup] = await Promise.all([\n page.waitForEvent('popup'),\n page.evaluate(() => window.open('https://example.com')),\n]);\nconsole.log(await popup.evaluate('location.href'));\n```\n\n**NOTE** Use `page.waitForLoadState([state[, options]])` to wait until the page gets to a particular state (you should not need it in most cases).", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "request": { + "kind": "event", + "name": "request", + "type": { + "name": "Request", + "properties": {} + }, + "comment": "Emitted when a page issues a request. The request object is read-only.\nIn order to intercept and mutate requests, see `page.route()` or `browserContext.route()`.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "requestfailed": { + "kind": "event", + "name": "requestfailed", + "type": { + "name": "Request", + "properties": {} + }, + "comment": "Emitted when a request fails, for example by timing out.\n\n**NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with `'requestfinished'` event and not with `'requestfailed'`.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "requestfinished": { + "kind": "event", + "name": "requestfinished", + "type": { + "name": "Request", + "properties": {} + }, + "comment": "Emitted when a request finishes successfully after downloading the response body. For a successful response, the sequence of events is `request`, `response` and `requestfinished`.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "response": { + "kind": "event", + "name": "response", + "type": { + "name": "Response", + "properties": {} + }, + "comment": "Emitted when response status and headers are received for a request. For a successful response, the sequence of events is `request`, `response` and `requestfinished`.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "worker": { + "kind": "event", + "name": "worker", + "type": { + "name": "Worker", + "properties": {} + }, + "comment": "Emitted when a dedicated WebWorker is spawned by the page.", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "$": { + "kind": "method", + "name": "$", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The method finds an element matching the specified selector within the page. If no elements match the selector, the return value resolves to `null`.\nShortcut for page.mainFrame().$(selector).", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "selector": { + "kind": "property", + "name": "selector", + "type": { + "name": "string", + "properties": {} + }, + "comment": "A selector to query page for. See working with selectors for more details.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "$$": { + "kind": "method", + "name": "$$", + "type": { + "name": "Promise>", + "properties": {} + }, + "comment": "The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.\nShortcut for page.mainFrame().$$(selector).", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "selector": { + "kind": "property", + "name": "selector", + "type": { + "name": "string", + "properties": {} + }, + "comment": "A selector to query page for. See working with selectors for more details.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "$eval": { + "kind": "method", + "name": "$eval", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The method finds an element matching the specified selector within the page and passes it as a first argument to `pageFunction`. If no elements match the selector, the method throws an error.\nIf `pageFunction` returns a Promise, then `page.$eval` would wait for the promise to resolve and return its value.\nExamples:\n```js\nconst searchValue = await page.$eval('#search', el => el.value);\nconst preloadHref = await page.$eval('link[rel=preload]', el => el.href);\nconst html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');\n```\nShortcut for page.mainFrame().$eval(selector, pageFunction).", + "returnComment": "Promise which resolves to the return value of `pageFunction`", + "required": true, + "templates": [], + "args": { + "selector": { + "kind": "property", + "name": "selector", + "type": { + "name": "string", + "properties": {} + }, + "comment": "A selector to query page for. See working with selectors for more details.", + "returnComment": "", + "required": true, + "templates": [] + }, + "pageFunction": { + "kind": "property", + "name": "pageFunction", + "type": { + "name": "function(Element)", + "properties": {} + }, + "comment": "Function to be evaluated in browser context", + "returnComment": "", + "required": true, + "templates": [] + }, + "arg": { + "kind": "property", + "name": "arg", + "type": { + "name": "EvaluationArgument", + "properties": {} + }, + "comment": "Optional argument to pass to `pageFunction`", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "$$eval": { + "kind": "method", + "name": "$$eval", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The method finds all elements matching the specified selector within the page and passes an array of matched elements as a first argument to `pageFunction`.\nIf `pageFunction` returns a Promise, then `page.$$eval` would wait for the promise to resolve and return its value.\nExamples:\n```js\nconst divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);\n```", + "returnComment": "Promise which resolves to the return value of `pageFunction`", + "required": true, + "templates": [], + "args": { + "selector": { + "kind": "property", + "name": "selector", + "type": { + "name": "string", + "properties": {} + }, + "comment": "A selector to query page for. See working with selectors for more details.", + "returnComment": "", + "required": true, + "templates": [] + }, + "pageFunction": { + "kind": "property", + "name": "pageFunction", + "type": { + "name": "function(Array)", + "properties": {} + }, + "comment": "Function to be evaluated in browser context", + "returnComment": "", + "required": true, + "templates": [] + }, + "arg": { + "kind": "property", + "name": "arg", + "type": { + "name": "EvaluationArgument", + "properties": {} + }, + "comment": "Optional argument to pass to `pageFunction`", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "accessibility": { + "kind": "property", + "name": "accessibility", + "type": { + "name": "Accessibility", + "properties": {} + }, + "comment": "", + "returnComment": "", + "required": true, + "templates": [], + "args": {} + }, + "addInitScript": { + "kind": "method", + "name": "addInitScript", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Adds a script which would be evaluated in one of the following scenarios:\n\nWhenever the page is navigated.\nWhenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.\n\nThe script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`.\nAn example of overriding `Math.random` before the page loads:\n```js\n// preload.js\nMath.random = () => 42;\n\n// In your playwright script, assuming the preload.js file is in same folder\nconst preloadFile = fs.readFileSync('./preload.js', 'utf8');\nawait page.addInitScript(preloadFile);\n```\n\n**NOTE** The order of evaluation of multiple scripts installed via browserContext.addInitScript(script[, arg]) and page.addInitScript(script[, arg]) is not defined.", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "script": { + "kind": "property", + "name": "script", + "type": { + "name": "function|string|Object", + "properties": { + "path": { + "kind": "property", + "name": "path", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to current working directory.", + "returnComment": "", + "required": false, + "templates": [] + }, + "content": { + "kind": "property", + "name": "content", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Raw script content.", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "comment": "Script to be evaluated in the page.", + "returnComment": "", + "required": true, + "templates": [] + }, + "arg": { + "kind": "property", + "name": "arg", + "type": { + "name": "Serializable", + "properties": {} + }, + "comment": "Optional argument to pass to `script` (only supported when passing a function).", + "returnComment": "", + "required": false, + "templates": [] + } + } + }, + "addScriptTag": { + "kind": "method", + "name": "addScriptTag", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "Adds a `\n \n
    \n `);\n await page.click('button');\n})();\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "name": { + "kind": "property", + "name": "name", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Name of the function on the window object.", + "returnComment": "", + "required": true, + "templates": [] + }, + "playwrightBinding": { + "kind": "property", + "name": "playwrightBinding", + "type": { + "name": "function", + "properties": {} + }, + "comment": "Callback function that will be called in the Playwright's context.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "exposeFunction": { + "kind": "method", + "name": "exposeFunction", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "The method adds a function called `name` on the `window` object of every frame in the page.\nWhen called, the function executes `playwrightFunction` in Node.js and returns a Promise which resolves to the return value of `playwrightFunction`.\nIf the `playwrightFunction` returns a Promise, it will be awaited.\nSee browserContext.exposeFunction(name, playwrightFunction) for context-wide exposed function.\n\n**NOTE** Functions installed via `page.exposeFunction` survive navigations.\n\nAn example of adding an `md5` function to the page:\n```js\nconst { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.\nconst crypto = require('crypto');\n\n(async () => {\n const browser = await webkit.launch({ headless: false });\n const page = await browser.newPage();\n await page.exposeFunction('md5', text => crypto.createHash('md5').update(text).digest('hex'));\n await page.setContent(`\n \n \n
    \n `);\n await page.click('button');\n})();\n```\nAn example of adding a `window.readfile` function to the page:\n```js\nconst { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.\nconst fs = require('fs');\n\n(async () => {\n const browser = await chromium.launch();\n const page = await browser.newPage();\n page.on('console', msg => console.log(msg.text()));\n await page.exposeFunction('readfile', async filePath => {\n return new Promise((resolve, reject) => {\n fs.readFile(filePath, 'utf8', (err, text) => {\n if (err)\n reject(err);\n else\n resolve(text);\n });\n });\n });\n await page.evaluate(async () => {\n // use window.readfile to read contents of a file\n const content = await window.readfile('/etc/hosts');\n console.log(content);\n });\n await browser.close();\n})();\n```", + "returnComment": "", + "required": true, + "templates": [], + "args": { + "name": { + "kind": "property", + "name": "name", + "type": { + "name": "string", + "properties": {} + }, + "comment": "Name of the function on the window object", + "returnComment": "", + "required": true, + "templates": [] + }, + "playwrightFunction": { + "kind": "property", + "name": "playwrightFunction", + "type": { + "name": "function", + "properties": {} + }, + "comment": "Callback function which will be called in Playwright's context.", + "returnComment": "", + "required": true, + "templates": [] + } + } + }, + "fill": { + "kind": "method", + "name": "fill", + "type": { + "name": "Promise", + "properties": {} + }, + "comment": "This method waits for an element matching `selector`, waits for actionability checks, focuses the element, fills it and triggers an `input` event after filling.\nIf the element matching `selector` is not an ``, `