patchright-core 1.51.2 → 1.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browsers.json +15 -13
- package/lib/androidServerImpl.js +42 -48
- package/lib/browserServerImpl.js +54 -67
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +312 -328
- package/lib/cli/programWithTestStub.js +51 -45
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +141 -228
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -36
- package/lib/client/browser.js +57 -61
- package/lib/client/browserContext.js +297 -326
- package/lib/client/browserType.js +92 -106
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +82 -95
- package/lib/client/clientHelper.js +46 -38
- package/lib/client/clientInstrumentation.js +40 -37
- package/lib/client/clientStackTrace.js +41 -37
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +190 -212
- package/lib/client/consoleMessage.js +31 -28
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +73 -75
- package/lib/client/elementHandle.js +111 -147
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +124 -121
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +135 -158
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +31 -28
- package/lib/client/frame.js +187 -306
- package/lib/client/harRouter.js +42 -52
- package/lib/client/input.js +40 -69
- package/lib/client/jsHandle.js +54 -69
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +29 -28
- package/lib/client/locator.js +161 -245
- package/lib/client/network.js +277 -295
- package/lib/client/page.js +270 -318
- package/lib/client/platform.js +46 -43
- package/lib/client/playwright.js +51 -66
- package/lib/client/selectors.js +48 -46
- package/lib/client/stream.js +29 -25
- package/lib/client/timeoutSettings.js +49 -39
- package/lib/client/tracing.js +48 -84
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +69 -88
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +61 -56
- package/lib/client/worker.js +48 -58
- package/lib/client/writableStream.js +27 -23
- package/lib/generated/clockSource.js +26 -5
- package/lib/generated/consoleApiSource.js +26 -5
- package/lib/generated/injectedScriptSource.js +26 -5
- package/lib/generated/pollingRecorderSource.js +26 -5
- package/lib/generated/utilityScriptSource.js +26 -5
- package/lib/generated/webSocketMockSource.js +375 -4
- package/lib/inProcessFactory.js +53 -53
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +53 -46
- package/lib/protocol/debug.js +209 -25
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2714 -2714
- package/lib/protocol/validatorPrimitives.js +114 -73
- package/lib/remote/playwrightConnection.js +140 -157
- package/lib/remote/playwrightServer.js +99 -84
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +216 -209
- package/lib/server/android/backendAdb.js +89 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +221 -155
- package/lib/server/bidi/bidiChromium.js +106 -79
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +128 -113
- package/lib/server/bidi/bidiFirefox.js +76 -69
- package/lib/server/bidi/bidiInput.js +86 -97
- package/lib/server/bidi/bidiNetworkManager.js +137 -154
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +247 -219
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
- package/lib/server/bidi/third_party/bidiProtocol.js +144 -131
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
- package/lib/server/browser.js +76 -84
- package/lib/server/browserContext.js +321 -346
- package/lib/server/browserType.js +169 -182
- package/lib/server/callLog.js +47 -44
- package/lib/server/chromium/chromium.js +212 -190
- package/lib/server/chromium/chromiumSwitches.js +86 -64
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +253 -273
- package/lib/server/chromium/crConnection.js +91 -116
- package/lib/server/chromium/crCoverage.js +113 -127
- package/lib/server/chromium/crDevTools.js +59 -51
- package/lib/server/chromium/crDragDrop.js +62 -79
- package/lib/server/chromium/crExecutionContext.js +88 -83
- package/lib/server/chromium/crInput.js +97 -95
- package/lib/server/chromium/crNetworkManager.js +288 -403
- package/lib/server/chromium/crPage.js +522 -608
- package/lib/server/chromium/crPdf.js +54 -86
- package/lib/server/chromium/crProtocolHelper.js +92 -80
- package/lib/server/chromium/crServiceWorker.js +82 -67
- package/lib/server/chromium/defaultFontFamilies.js +152 -135
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +65 -99
- package/lib/server/clock.js +62 -50
- package/lib/server/codegen/csharp.js +185 -160
- package/lib/server/codegen/java.js +155 -128
- package/lib/server/codegen/javascript.js +163 -148
- package/lib/server/codegen/jsonl.js +32 -28
- package/lib/server/codegen/language.js +75 -52
- package/lib/server/codegen/languages.js +65 -27
- package/lib/server/codegen/python.js +140 -125
- package/lib/server/codegen/types.js +15 -4
- package/lib/server/console.js +28 -32
- package/lib/server/cookieStore.js +105 -86
- package/lib/server/debugController.js +97 -124
- package/lib/server/debugger.js +82 -78
- package/lib/server/deviceDescriptors.js +37 -24
- package/lib/server/deviceDescriptorsSource.json +50 -50
- package/lib/server/dialog.js +36 -35
- package/lib/server/dispatchers/androidDispatcher.js +196 -107
- package/lib/server/dispatchers/artifactDispatcher.js +62 -62
- package/lib/server/dispatchers/browserContextDispatcher.js +176 -205
- package/lib/server/dispatchers/browserDispatcher.js +78 -97
- package/lib/server/dispatchers/browserTypeDispatcher.js +35 -35
- package/lib/server/dispatchers/cdpSessionDispatcher.js +32 -36
- package/lib/server/dispatchers/debugControllerDispatcher.js +48 -66
- package/lib/server/dispatchers/dialogDispatcher.js +30 -27
- package/lib/server/dispatchers/dispatcher.js +169 -220
- package/lib/server/dispatchers/electronDispatcher.js +54 -57
- package/lib/server/dispatchers/elementHandlerDispatcher.js +77 -119
- package/lib/server/dispatchers/frameDispatcher.js +99 -163
- package/lib/server/dispatchers/jsHandleDispatcher.js +49 -66
- package/lib/server/dispatchers/jsonPipeDispatcher.js +35 -36
- package/lib/server/dispatchers/localUtilsDispatcher.js +95 -80
- package/lib/server/dispatchers/networkDispatchers.js +90 -107
- package/lib/server/dispatchers/pageDispatcher.js +128 -169
- package/lib/server/dispatchers/playwrightDispatcher.js +69 -76
- package/lib/server/dispatchers/selectorsDispatcher.js +28 -24
- package/lib/server/dispatchers/streamDispatcher.js +42 -45
- package/lib/server/dispatchers/tracingDispatcher.js +36 -41
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +96 -131
- package/lib/server/dispatchers/writableStreamDispatcher.js +54 -38
- package/lib/server/dom.js +413 -443
- package/lib/server/download.js +45 -35
- package/lib/server/electron/electron.js +156 -176
- package/lib/server/electron/loader.js +8 -36
- package/lib/server/errors.js +47 -46
- package/lib/server/fetch.js +289 -323
- package/lib/server/fileChooser.js +25 -24
- package/lib/server/fileUploadUtils.js +65 -59
- package/lib/server/firefox/ffAccessibility.js +153 -131
- package/lib/server/firefox/ffBrowser.js +213 -277
- package/lib/server/firefox/ffConnection.js +63 -84
- package/lib/server/firefox/ffExecutionContext.js +91 -73
- package/lib/server/firefox/ffInput.js +67 -69
- package/lib/server/firefox/ffNetworkManager.js +131 -110
- package/lib/server/firefox/ffPage.js +236 -273
- package/lib/server/firefox/firefox.js +76 -67
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +107 -35
- package/lib/server/frameSelectors.js +77 -111
- package/lib/server/frames.js +741 -891
- package/lib/server/har/harRecorder.js +85 -77
- package/lib/server/har/harTracer.js +287 -222
- package/lib/server/harBackend.js +80 -80
- package/lib/server/helper.js +56 -59
- package/lib/server/index.js +59 -99
- package/lib/server/input.js +134 -163
- package/lib/server/instrumentation.js +49 -44
- package/lib/server/javascript.js +143 -134
- package/lib/server/launchApp.js +92 -73
- package/lib/server/localUtils.js +130 -122
- package/lib/server/macEditingCommands.js +141 -137
- package/lib/server/network.js +262 -296
- package/lib/server/page.js +329 -426
- package/lib/server/pageBinding.js +88 -0
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +60 -67
- package/lib/server/progress.js +56 -51
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +70 -86
- package/lib/server/recorder/contextRecorder.js +134 -138
- package/lib/server/recorder/recorderApp.js +127 -136
- package/lib/server/recorder/recorderCollection.js +56 -44
- package/lib/server/recorder/recorderFrontend.js +15 -4
- package/lib/server/recorder/recorderRunner.js +79 -103
- package/lib/server/recorder/recorderUtils.js +56 -45
- package/lib/server/recorder/throttledFile.js +42 -30
- package/lib/server/recorder.js +177 -186
- package/lib/server/registry/browserFetcher.js +106 -101
- package/lib/server/registry/dependencies.js +245 -196
- package/lib/server/registry/index.js +904 -792
- package/lib/server/registry/nativeDeps.js +1073 -464
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +166 -182
- package/lib/server/selectors.js +85 -46
- package/lib/server/socksClientCertificatesInterceptor.js +166 -185
- package/lib/server/socksInterceptor.js +62 -70
- package/lib/server/storageScript.js +94 -100
- package/lib/server/timeoutSettings.js +58 -43
- package/lib/server/trace/recorder/snapshotter.js +70 -89
- package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
- package/lib/server/trace/recorder/tracing.js +321 -333
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +168 -146
- package/lib/server/transport.js +124 -133
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +39 -26
- package/lib/server/utils/comparators.js +105 -103
- package/lib/server/utils/crypto.js +157 -112
- package/lib/server/utils/debug.js +37 -28
- package/lib/server/utils/debugLogger.js +69 -48
- package/lib/server/utils/env.js +52 -37
- package/lib/server/utils/eventsHelper.js +29 -28
- package/lib/server/utils/expectUtils.js +31 -26
- package/lib/server/utils/fileUtils.js +123 -136
- package/lib/server/utils/happyEyeballs.js +138 -123
- package/lib/server/utils/hostPlatform.js +84 -120
- package/lib/server/utils/httpServer.js +106 -121
- package/lib/server/utils/image_tools/colorUtils.js +42 -51
- package/lib/server/utils/image_tools/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +38 -30
- package/lib/server/utils/image_tools/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +50 -37
- package/lib/server/utils/network.js +143 -86
- package/lib/server/utils/nodePlatform.js +87 -79
- package/lib/server/utils/pipeTransport.js +44 -42
- package/lib/server/utils/processLauncher.js +111 -121
- package/lib/server/utils/profiler.js +52 -39
- package/lib/server/utils/socksProxy.js +280 -339
- package/lib/server/utils/spawnAsync.js +37 -41
- package/lib/server/utils/task.js +31 -38
- package/lib/server/utils/userAgent.js +73 -66
- package/lib/server/utils/wsServer.js +73 -69
- package/lib/server/utils/zipFile.js +36 -37
- package/lib/server/utils/zones.js +37 -34
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +76 -63
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +159 -176
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +84 -70
- package/lib/server/webkit/wkInput.js +82 -80
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +525 -619
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +77 -77
- package/lib/utils/isomorphic/ariaSnapshot.js +144 -152
- package/lib/utils/isomorphic/assert.js +28 -22
- package/lib/utils/isomorphic/builtins.js +90 -0
- package/lib/utils/isomorphic/colors.js +66 -59
- package/lib/utils/isomorphic/cssParser.js +121 -125
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +38 -37
- package/lib/utils/isomorphic/locatorGenerators.js +340 -357
- package/lib/utils/isomorphic/locatorParser.js +96 -105
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +47 -39
- package/lib/utils/isomorphic/mimeType.js +448 -25
- package/lib/utils/isomorphic/multimap.js +35 -27
- package/lib/utils/isomorphic/rtti.js +35 -33
- package/lib/utils/isomorphic/selectorParser.js +183 -193
- package/lib/utils/isomorphic/semaphore.js +27 -24
- package/lib/utils/isomorphic/stackTrace.js +87 -98
- package/lib/utils/isomorphic/stringUtils.js +113 -106
- package/lib/utils/isomorphic/time.js +41 -22
- package/lib/utils/isomorphic/timeoutRunner.js +55 -54
- package/lib/utils/isomorphic/traceUtils.js +38 -41
- package/lib/utils/isomorphic/types.js +15 -4
- package/lib/utils/isomorphic/urlMatch.js +112 -67
- package/lib/utils/isomorphic/utilityScriptSerializers.js +248 -0
- package/lib/utils.js +97 -443
- package/lib/utilsBundle.js +101 -52
- package/lib/vite/htmlReport/index.html +21 -15
- package/lib/vite/recorder/assets/{codeMirrorModule-B9YMkrwa.js → codeMirrorModule-DVQi6prl.js} +1 -1
- package/lib/vite/recorder/assets/index-97EUAAbk.js +184 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-DpJ-EmBQ.js → codeMirrorModule-dvXVzLxY.js} +1 -1
- package/lib/vite/traceViewer/assets/defaultSettingsView-BjymbO6M.js +265 -0
- package/lib/vite/traceViewer/{defaultSettingsView.5fN5lw10.css → defaultSettingsView.QdHITyLI.css} +1 -1
- package/lib/vite/traceViewer/index.ChIUCJnj.js +2 -0
- package/lib/vite/traceViewer/index.html +3 -3
- package/lib/vite/traceViewer/sw.bundle.js +3 -3
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/vite/traceViewer/uiMode.jUCiCtdp.js +5 -0
- package/lib/zipBundle.js +32 -23
- package/package.json +1 -1
- package/types/protocol.d.ts +436 -17
- package/types/types.d.ts +35 -16
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
- package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
- package/lib/vite/traceViewer/assets/defaultSettingsView-DTenqiGw.js +0 -259
- package/lib/vite/traceViewer/index.CUq7VgrV.js +0 -2
- package/lib/vite/traceViewer/uiMode.CHJSAD7F.js +0 -5
package/lib/cli/program.js
CHANGED
|
@@ -1,134 +1,173 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var program_exports = {};
|
|
30
|
+
__export(program_exports, {
|
|
31
|
+
program: () => import_utilsBundle2.program
|
|
11
32
|
});
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* You may obtain a copy of the License at
|
|
31
|
-
*
|
|
32
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
-
*
|
|
34
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
35
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
37
|
-
* See the License for the specific language governing permissions and
|
|
38
|
-
* limitations under the License.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/* eslint-disable no-console */
|
|
42
|
-
|
|
43
|
-
const packageJSON = require('../../package.json');
|
|
44
|
-
_utilsBundle.program.version('Version ' + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)).name(buildBasePlaywrightCLICommand(process.env.PW_LANG_NAME));
|
|
45
|
-
_utilsBundle.program.command('mark-docker-image [dockerImageNameTemplate]', {
|
|
46
|
-
hidden: true
|
|
47
|
-
}).description('mark docker image').allowUnknownOption(true).action(function (dockerImageNameTemplate) {
|
|
48
|
-
(0, _utils.assert)(dockerImageNameTemplate, 'dockerImageNameTemplate is required');
|
|
49
|
-
(0, _server.writeDockerVersion)(dockerImageNameTemplate).catch(logErrorAndExit);
|
|
33
|
+
module.exports = __toCommonJS(program_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_os = __toESM(require("os"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var playwright = __toESM(require("../.."));
|
|
38
|
+
var import_driver = require("./driver");
|
|
39
|
+
var import_server = require("../server");
|
|
40
|
+
var import_utils = require("../utils");
|
|
41
|
+
var import_traceViewer = require("../server/trace/viewer/traceViewer");
|
|
42
|
+
var import_utils2 = require("../utils");
|
|
43
|
+
var import_ascii = require("../server/utils/ascii");
|
|
44
|
+
var import_utilsBundle = require("../utilsBundle");
|
|
45
|
+
var import_utilsBundle2 = require("../utilsBundle");
|
|
46
|
+
const packageJSON = require("../../package.json");
|
|
47
|
+
import_utilsBundle.program.version("Version " + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)).name(buildBasePlaywrightCLICommand(process.env.PW_LANG_NAME));
|
|
48
|
+
import_utilsBundle.program.command("mark-docker-image [dockerImageNameTemplate]", { hidden: true }).description("mark docker image").allowUnknownOption(true).action(function(dockerImageNameTemplate) {
|
|
49
|
+
(0, import_utils2.assert)(dockerImageNameTemplate, "dockerImageNameTemplate is required");
|
|
50
|
+
(0, import_server.writeDockerVersion)(dockerImageNameTemplate).catch(logErrorAndExit);
|
|
50
51
|
});
|
|
51
|
-
commandWithOpenOptions(
|
|
52
|
+
commandWithOpenOptions("open [url]", "open page in browser specified via -b, --browser", []).action(function(url, options) {
|
|
52
53
|
open(options, url, codegenId()).catch(logErrorAndExit);
|
|
53
|
-
}).addHelpText(
|
|
54
|
+
}).addHelpText("afterAll", `
|
|
54
55
|
Examples:
|
|
55
56
|
|
|
56
57
|
$ open
|
|
57
58
|
$ open -b webkit https://example.com`);
|
|
58
|
-
commandWithOpenOptions(
|
|
59
|
+
commandWithOpenOptions(
|
|
60
|
+
"codegen [url]",
|
|
61
|
+
"open page and generate code for user actions",
|
|
62
|
+
[
|
|
63
|
+
["-o, --output <file name>", "saves the generated script to a file"],
|
|
64
|
+
["--target <language>", `language to generate, one of javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, java, java-junit`, codegenId()],
|
|
65
|
+
["--test-id-attribute <attributeName>", "use the specified attribute to generate data test ID selectors"]
|
|
66
|
+
]
|
|
67
|
+
).action(function(url, options) {
|
|
59
68
|
codegen(options, url).catch(logErrorAndExit);
|
|
60
|
-
}).addHelpText(
|
|
69
|
+
}).addHelpText("afterAll", `
|
|
61
70
|
Examples:
|
|
62
71
|
|
|
63
72
|
$ codegen
|
|
64
73
|
$ codegen --target=python
|
|
65
74
|
$ codegen -b webkit https://example.com`);
|
|
66
75
|
function suggestedBrowsersToInstall() {
|
|
67
|
-
return
|
|
76
|
+
return import_server.registry.executables().filter((e) => e.installType !== "none" && e.type !== "tool").map((e) => e.name).join(", ");
|
|
68
77
|
}
|
|
69
78
|
function defaultBrowsersToInstall(options) {
|
|
70
|
-
let executables =
|
|
71
|
-
if (options.noShell)
|
|
72
|
-
|
|
79
|
+
let executables = import_server.registry.defaultExecutables();
|
|
80
|
+
if (options.noShell)
|
|
81
|
+
executables = executables.filter((e) => e.name !== "chromium-headless-shell");
|
|
82
|
+
if (options.onlyShell)
|
|
83
|
+
executables = executables.filter((e) => e.name !== "chromium");
|
|
73
84
|
return executables;
|
|
74
85
|
}
|
|
75
86
|
function checkBrowsersToInstall(args, options) {
|
|
76
|
-
if (options.noShell && options.onlyShell)
|
|
87
|
+
if (options.noShell && options.onlyShell)
|
|
88
|
+
throw new Error(`Only one of --no-shell and --only-shell can be specified`);
|
|
77
89
|
const faultyArguments = [];
|
|
78
90
|
const executables = [];
|
|
79
|
-
const handleArgument = arg => {
|
|
80
|
-
const executable =
|
|
81
|
-
if (!executable || executable.installType ===
|
|
82
|
-
|
|
91
|
+
const handleArgument = (arg) => {
|
|
92
|
+
const executable = import_server.registry.findExecutable(arg);
|
|
93
|
+
if (!executable || executable.installType === "none")
|
|
94
|
+
faultyArguments.push(arg);
|
|
95
|
+
else
|
|
96
|
+
executables.push(executable);
|
|
97
|
+
if (executable?.browserName === "chromium")
|
|
98
|
+
executables.push(import_server.registry.findExecutable("ffmpeg"));
|
|
83
99
|
};
|
|
84
100
|
for (const arg of args) {
|
|
85
|
-
if (arg ===
|
|
86
|
-
if (!options.onlyShell)
|
|
87
|
-
|
|
101
|
+
if (arg === "chromium") {
|
|
102
|
+
if (!options.onlyShell)
|
|
103
|
+
handleArgument("chromium");
|
|
104
|
+
if (!options.noShell)
|
|
105
|
+
handleArgument("chromium-headless-shell");
|
|
88
106
|
} else {
|
|
89
107
|
handleArgument(arg);
|
|
90
108
|
}
|
|
91
109
|
}
|
|
92
|
-
if (process.platform ===
|
|
93
|
-
|
|
110
|
+
if (process.platform === "win32")
|
|
111
|
+
executables.push(import_server.registry.findExecutable("winldd"));
|
|
112
|
+
if (faultyArguments.length)
|
|
113
|
+
throw new Error(`Invalid installation targets: ${faultyArguments.map((name) => `'${name}'`).join(", ")}. Expecting one of: ${suggestedBrowsersToInstall()}`);
|
|
94
114
|
return executables;
|
|
95
115
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if ((0,
|
|
100
|
-
console.error((0,
|
|
116
|
+
import_utilsBundle.program.command("install [browser...]").description("ensure browsers necessary for this version of Playwright are installed").option("--with-deps", "install system dependencies for browsers").option("--dry-run", "do not execute installation, only print information").option("--force", "force reinstall of stable browser channels").option("--only-shell", "only install headless shell when installing chromium").option("--no-shell", "do not install chromium headless shell").action(async function(args, options) {
|
|
117
|
+
if (options.shell === false)
|
|
118
|
+
options.noShell = true;
|
|
119
|
+
if ((0, import_utils.isLikelyNpxGlobal)()) {
|
|
120
|
+
console.error((0, import_ascii.wrapInASCIIBox)([
|
|
121
|
+
`WARNING: It looks like you are running 'npx playwright install' without first`,
|
|
122
|
+
`installing your project's dependencies.`,
|
|
123
|
+
``,
|
|
124
|
+
`To avoid unexpected behavior, please install your dependencies first, and`,
|
|
125
|
+
`then run Playwright's install command:`,
|
|
126
|
+
``,
|
|
127
|
+
` npm install`,
|
|
128
|
+
` npx playwright install`,
|
|
129
|
+
``,
|
|
130
|
+
`If your project does not yet depend on Playwright, first install the`,
|
|
131
|
+
`applicable npm package (most commonly @playwright/test), and`,
|
|
132
|
+
`then run Playwright's install command to download the browsers:`,
|
|
133
|
+
``,
|
|
134
|
+
` npm install @playwright/test`,
|
|
135
|
+
` npx playwright install`,
|
|
136
|
+
``
|
|
137
|
+
].join("\n"), 1));
|
|
101
138
|
}
|
|
102
139
|
try {
|
|
103
140
|
const hasNoArguments = !args.length;
|
|
104
141
|
const executables = hasNoArguments ? defaultBrowsersToInstall(options) : checkBrowsersToInstall(args, options);
|
|
105
|
-
if (options.withDeps)
|
|
142
|
+
if (options.withDeps)
|
|
143
|
+
await import_server.registry.installDeps(executables, !!options.dryRun);
|
|
106
144
|
if (options.dryRun) {
|
|
107
145
|
for (const executable of executables) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
console.log(`
|
|
111
|
-
|
|
112
|
-
if ((_executable$downloadU = executable.downloadURLs) !== null && _executable$downloadU !== void 0 && _executable$downloadU.length) {
|
|
146
|
+
const version = executable.browserVersion ? `version ` + executable.browserVersion : "";
|
|
147
|
+
console.log(`browser: ${executable.name}${version ? " " + version : ""}`);
|
|
148
|
+
console.log(` Install location: ${executable.directory ?? "<system>"}`);
|
|
149
|
+
if (executable.downloadURLs?.length) {
|
|
113
150
|
const [url, ...fallbacks] = executable.downloadURLs;
|
|
114
151
|
console.log(` Download url: ${url}`);
|
|
115
|
-
for (let i = 0; i < fallbacks.length; ++i)
|
|
152
|
+
for (let i = 0; i < fallbacks.length; ++i)
|
|
153
|
+
console.log(` Download fallback ${i + 1}: ${fallbacks[i]}`);
|
|
116
154
|
}
|
|
117
155
|
console.log(``);
|
|
118
156
|
}
|
|
119
157
|
} else {
|
|
120
158
|
const forceReinstall = hasNoArguments ? false : !!options.force;
|
|
121
|
-
await
|
|
122
|
-
await
|
|
123
|
-
e.name =
|
|
159
|
+
await import_server.registry.install(executables, forceReinstall);
|
|
160
|
+
await import_server.registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || "javascript").catch((e) => {
|
|
161
|
+
e.name = "Playwright Host validation warning";
|
|
124
162
|
console.error(e);
|
|
125
163
|
});
|
|
126
164
|
}
|
|
127
165
|
} catch (e) {
|
|
128
|
-
console.log(`Failed to install browsers
|
|
129
|
-
|
|
166
|
+
console.log(`Failed to install browsers
|
|
167
|
+
${e}`);
|
|
168
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
|
|
130
169
|
}
|
|
131
|
-
}).addHelpText(
|
|
170
|
+
}).addHelpText("afterAll", `
|
|
132
171
|
|
|
133
172
|
Examples:
|
|
134
173
|
- $ install
|
|
@@ -136,106 +175,110 @@ Examples:
|
|
|
136
175
|
|
|
137
176
|
- $ install chrome firefox
|
|
138
177
|
Install custom browsers, supports ${suggestedBrowsersToInstall()}.`);
|
|
139
|
-
|
|
178
|
+
import_utilsBundle.program.command("uninstall").description("Removes browsers used by this installation of Playwright from the system (chromium, firefox, webkit, ffmpeg). This does not include branded channels.").option("--all", "Removes all browsers used by any Playwright installation from the system.").action(async (options) => {
|
|
140
179
|
delete process.env.PLAYWRIGHT_SKIP_BROWSER_GC;
|
|
141
|
-
await
|
|
142
|
-
numberOfBrowsersLeft
|
|
143
|
-
}) => {
|
|
180
|
+
await import_server.registry.uninstall(!!options.all).then(({ numberOfBrowsersLeft }) => {
|
|
144
181
|
if (!options.all && numberOfBrowsersLeft > 0) {
|
|
145
|
-
console.log(
|
|
146
|
-
console.log(`There are still ${numberOfBrowsersLeft} browsers left, used by other Playwright installations
|
|
182
|
+
console.log("Successfully uninstalled Playwright browsers for the current Playwright installation.");
|
|
183
|
+
console.log(`There are still ${numberOfBrowsersLeft} browsers left, used by other Playwright installations.
|
|
184
|
+
To uninstall Playwright browsers for all installations, re-run with --all flag.`);
|
|
147
185
|
}
|
|
148
186
|
}).catch(logErrorAndExit);
|
|
149
187
|
});
|
|
150
|
-
|
|
188
|
+
import_utilsBundle.program.command("install-deps [browser...]").description("install dependencies necessary to run browsers (will ask for sudo permissions)").option("--dry-run", "Do not execute installation commands, only print them").action(async function(args, options) {
|
|
151
189
|
try {
|
|
152
|
-
if (!args.length)
|
|
190
|
+
if (!args.length)
|
|
191
|
+
await import_server.registry.installDeps(defaultBrowsersToInstall({}), !!options.dryRun);
|
|
192
|
+
else
|
|
193
|
+
await import_server.registry.installDeps(checkBrowsersToInstall(args, {}), !!options.dryRun);
|
|
153
194
|
} catch (e) {
|
|
154
|
-
console.log(`Failed to install browser dependencies
|
|
155
|
-
|
|
195
|
+
console.log(`Failed to install browser dependencies
|
|
196
|
+
${e}`);
|
|
197
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
|
|
156
198
|
}
|
|
157
|
-
}).addHelpText(
|
|
199
|
+
}).addHelpText("afterAll", `
|
|
158
200
|
Examples:
|
|
159
201
|
- $ install-deps
|
|
160
202
|
Install dependencies for default browsers.
|
|
161
203
|
|
|
162
204
|
- $ install-deps chrome firefox
|
|
163
205
|
Install dependencies for specific browsers, supports ${suggestedBrowsersToInstall()}.`);
|
|
164
|
-
const browsers = [
|
|
165
|
-
alias:
|
|
166
|
-
name:
|
|
167
|
-
type:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
name
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
alias: 'wk',
|
|
174
|
-
name: 'WebKit',
|
|
175
|
-
type: 'webkit'
|
|
176
|
-
}];
|
|
177
|
-
for (const {
|
|
178
|
-
alias,
|
|
179
|
-
name,
|
|
180
|
-
type
|
|
181
|
-
} of browsers) {
|
|
182
|
-
commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, []).action(function (url, options) {
|
|
183
|
-
open({
|
|
184
|
-
...options,
|
|
185
|
-
browser: type
|
|
186
|
-
}, url, options.target).catch(logErrorAndExit);
|
|
187
|
-
}).addHelpText('afterAll', `
|
|
206
|
+
const browsers = [
|
|
207
|
+
{ alias: "cr", name: "Chromium", type: "chromium" },
|
|
208
|
+
{ alias: "ff", name: "Firefox", type: "firefox" },
|
|
209
|
+
{ alias: "wk", name: "WebKit", type: "webkit" }
|
|
210
|
+
];
|
|
211
|
+
for (const { alias, name, type } of browsers) {
|
|
212
|
+
commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, []).action(function(url, options) {
|
|
213
|
+
open({ ...options, browser: type }, url, options.target).catch(logErrorAndExit);
|
|
214
|
+
}).addHelpText("afterAll", `
|
|
188
215
|
Examples:
|
|
189
216
|
|
|
190
217
|
$ ${alias} https://example.com`);
|
|
191
218
|
}
|
|
192
|
-
commandWithOpenOptions(
|
|
219
|
+
commandWithOpenOptions(
|
|
220
|
+
"screenshot <url> <filename>",
|
|
221
|
+
"capture a page screenshot",
|
|
222
|
+
[
|
|
223
|
+
["--wait-for-selector <selector>", "wait for selector before taking a screenshot"],
|
|
224
|
+
["--wait-for-timeout <timeout>", "wait for timeout in milliseconds before taking a screenshot"],
|
|
225
|
+
["--full-page", "whether to take a full page screenshot (entire scrollable area)"]
|
|
226
|
+
]
|
|
227
|
+
).action(function(url, filename, command) {
|
|
193
228
|
screenshot(command, command, url, filename).catch(logErrorAndExit);
|
|
194
|
-
}).addHelpText(
|
|
229
|
+
}).addHelpText("afterAll", `
|
|
195
230
|
Examples:
|
|
196
231
|
|
|
197
232
|
$ screenshot -b webkit https://example.com example.png`);
|
|
198
|
-
commandWithOpenOptions(
|
|
233
|
+
commandWithOpenOptions(
|
|
234
|
+
"pdf <url> <filename>",
|
|
235
|
+
"save page as pdf",
|
|
236
|
+
[
|
|
237
|
+
["--paper-format <format>", "paper format: Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6"],
|
|
238
|
+
["--wait-for-selector <selector>", "wait for given selector before saving as pdf"],
|
|
239
|
+
["--wait-for-timeout <timeout>", "wait for given timeout in milliseconds before saving as pdf"]
|
|
240
|
+
]
|
|
241
|
+
).action(function(url, filename, options) {
|
|
199
242
|
pdf(options, options, url, filename).catch(logErrorAndExit);
|
|
200
|
-
}).addHelpText(
|
|
243
|
+
}).addHelpText("afterAll", `
|
|
201
244
|
Examples:
|
|
202
245
|
|
|
203
246
|
$ pdf https://example.com example.pdf`);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}).action(function (options) {
|
|
207
|
-
(0, _driver.runDriver)();
|
|
247
|
+
import_utilsBundle.program.command("run-driver", { hidden: true }).action(function(options) {
|
|
248
|
+
(0, import_driver.runDriver)();
|
|
208
249
|
});
|
|
209
|
-
|
|
210
|
-
(0,
|
|
211
|
-
port: options.port ? +options.port :
|
|
250
|
+
import_utilsBundle.program.command("run-server").option("--port <port>", "Server port").option("--host <host>", "Server host").option("--path <path>", "Endpoint Path", "/").option("--max-clients <maxClients>", "Maximum clients").option("--mode <mode>", 'Server mode, either "default" or "extension"').action(function(options) {
|
|
251
|
+
(0, import_driver.runServer)({
|
|
252
|
+
port: options.port ? +options.port : void 0,
|
|
212
253
|
host: options.host,
|
|
213
254
|
path: options.path,
|
|
214
255
|
maxConnections: options.maxClients ? +options.maxClients : Infinity,
|
|
215
|
-
extension: options.mode ===
|
|
256
|
+
extension: options.mode === "extension" || !!process.env.PW_EXTENSION_MODE
|
|
216
257
|
}).catch(logErrorAndExit);
|
|
217
258
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}).action(function (options) {
|
|
221
|
-
(0, _driver.printApiJson)();
|
|
259
|
+
import_utilsBundle.program.command("print-api-json", { hidden: true }).action(function(options) {
|
|
260
|
+
(0, import_driver.printApiJson)();
|
|
222
261
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}).requiredOption('--browser <browserName>', 'Browser name, one of "chromium", "firefox" or "webkit"').option('--config <path-to-config-file>', 'JSON file with launchServer options').action(function (options) {
|
|
226
|
-
(0, _driver.launchBrowserServer)(options.browser, options.config);
|
|
262
|
+
import_utilsBundle.program.command("launch-server", { hidden: true }).requiredOption("--browser <browserName>", 'Browser name, one of "chromium", "firefox" or "webkit"').option("--config <path-to-config-file>", "JSON file with launchServer options").action(function(options) {
|
|
263
|
+
(0, import_driver.launchBrowserServer)(options.browser, options.config);
|
|
227
264
|
});
|
|
228
|
-
|
|
229
|
-
if (options.browser ===
|
|
230
|
-
|
|
231
|
-
if (options.browser ===
|
|
265
|
+
import_utilsBundle.program.command("show-trace [trace...]").option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("-h, --host <host>", "Host to serve trace on; specifying this option opens trace in a browser tab").option("-p, --port <port>", "Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab").option("--stdin", "Accept trace URLs over stdin to update the viewer").description("show trace viewer").action(function(traces, options) {
|
|
266
|
+
if (options.browser === "cr")
|
|
267
|
+
options.browser = "chromium";
|
|
268
|
+
if (options.browser === "ff")
|
|
269
|
+
options.browser = "firefox";
|
|
270
|
+
if (options.browser === "wk")
|
|
271
|
+
options.browser = "webkit";
|
|
232
272
|
const openOptions = {
|
|
233
273
|
host: options.host,
|
|
234
274
|
port: +options.port,
|
|
235
275
|
isServer: !!options.stdin
|
|
236
276
|
};
|
|
237
|
-
if (options.port !==
|
|
238
|
-
|
|
277
|
+
if (options.port !== void 0 || options.host !== void 0)
|
|
278
|
+
(0, import_traceViewer.runTraceInBrowser)(traces, openOptions).catch(logErrorAndExit);
|
|
279
|
+
else
|
|
280
|
+
(0, import_traceViewer.runTraceViewerApp)(traces, options.browser, openOptions, true).catch(logErrorAndExit);
|
|
281
|
+
}).addHelpText("afterAll", `
|
|
239
282
|
Examples:
|
|
240
283
|
|
|
241
284
|
$ show-trace https://example.com/trace.zip`);
|
|
@@ -243,79 +286,67 @@ async function launchContext(options, extraOptions) {
|
|
|
243
286
|
validateOptions(options);
|
|
244
287
|
const browserType = lookupBrowserType(options);
|
|
245
288
|
const launchOptions = extraOptions;
|
|
246
|
-
if (options.channel)
|
|
289
|
+
if (options.channel)
|
|
290
|
+
launchOptions.channel = options.channel;
|
|
247
291
|
launchOptions.handleSIGINT = false;
|
|
248
|
-
const contextOptions =
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
// In headless, keep things the way it works in Playwright by default.
|
|
256
|
-
// Assume high-dpi on MacOS. TODO: this is not perfect.
|
|
257
|
-
if (!extraOptions.headless) contextOptions.deviceScaleFactor = _os.default.platform() === 'darwin' ? 2 : 1;
|
|
258
|
-
|
|
259
|
-
// Work around the WebKit GTK scrolling issue.
|
|
260
|
-
if (browserType.name() === 'webkit' && process.platform === 'linux') {
|
|
292
|
+
const contextOptions = (
|
|
293
|
+
// Copy the device descriptor since we have to compare and modify the options.
|
|
294
|
+
options.device ? { ...playwright.devices[options.device] } : {}
|
|
295
|
+
);
|
|
296
|
+
if (!extraOptions.headless)
|
|
297
|
+
contextOptions.deviceScaleFactor = import_os.default.platform() === "darwin" ? 2 : 1;
|
|
298
|
+
if (browserType.name() === "webkit" && process.platform === "linux") {
|
|
261
299
|
delete contextOptions.hasTouch;
|
|
262
300
|
delete contextOptions.isMobile;
|
|
263
301
|
}
|
|
264
|
-
if (contextOptions.isMobile && browserType.name() ===
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
302
|
+
if (contextOptions.isMobile && browserType.name() === "firefox")
|
|
303
|
+
contextOptions.isMobile = void 0;
|
|
304
|
+
if (options.blockServiceWorkers)
|
|
305
|
+
contextOptions.serviceWorkers = "block";
|
|
269
306
|
if (options.proxyServer) {
|
|
270
307
|
launchOptions.proxy = {
|
|
271
308
|
server: options.proxyServer
|
|
272
309
|
};
|
|
273
|
-
if (options.proxyBypass)
|
|
310
|
+
if (options.proxyBypass)
|
|
311
|
+
launchOptions.proxy.bypass = options.proxyBypass;
|
|
274
312
|
}
|
|
275
313
|
const browser = await browserType.launch(launchOptions);
|
|
276
314
|
if (process.env.PWTEST_CLI_IS_UNDER_TEST) {
|
|
277
|
-
process._didSetSourcesForTest = text => {
|
|
278
|
-
process.stdout.write(
|
|
315
|
+
process._didSetSourcesForTest = (text) => {
|
|
316
|
+
process.stdout.write("\n-------------8<-------------\n");
|
|
279
317
|
process.stdout.write(text);
|
|
280
|
-
process.stdout.write(
|
|
318
|
+
process.stdout.write("\n-------------8<-------------\n");
|
|
281
319
|
const autoExitCondition = process.env.PWTEST_CLI_AUTO_EXIT_WHEN;
|
|
282
|
-
if (autoExitCondition && text.includes(autoExitCondition))
|
|
320
|
+
if (autoExitCondition && text.includes(autoExitCondition))
|
|
321
|
+
closeBrowser();
|
|
283
322
|
};
|
|
284
|
-
// Make sure we exit abnormally when browser crashes.
|
|
285
323
|
const logs = [];
|
|
286
|
-
require(
|
|
287
|
-
const line = require(
|
|
324
|
+
require("playwright-core/lib/utilsBundle").debug.log = (...args) => {
|
|
325
|
+
const line = require("util").format(...args) + "\n";
|
|
288
326
|
logs.push(line);
|
|
289
327
|
process.stderr.write(line);
|
|
290
328
|
};
|
|
291
|
-
browser.on(
|
|
292
|
-
const hasCrashLine = logs.some(line => line.includes(
|
|
329
|
+
browser.on("disconnected", () => {
|
|
330
|
+
const hasCrashLine = logs.some((line) => line.includes("process did exit:") && !line.includes("process did exit: exitCode=0, signal=null"));
|
|
293
331
|
if (hasCrashLine) {
|
|
294
|
-
process.stderr.write(
|
|
295
|
-
(0,
|
|
332
|
+
process.stderr.write("Detected browser crash.\n");
|
|
333
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
|
|
296
334
|
}
|
|
297
335
|
});
|
|
298
336
|
}
|
|
299
|
-
|
|
300
|
-
// Viewport size
|
|
301
337
|
if (options.viewportSize) {
|
|
302
338
|
try {
|
|
303
|
-
const [width, height] = options.viewportSize.split(
|
|
304
|
-
if (isNaN(width) || isNaN(height))
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
height
|
|
308
|
-
};
|
|
339
|
+
const [width, height] = options.viewportSize.split(",").map((n) => +n);
|
|
340
|
+
if (isNaN(width) || isNaN(height))
|
|
341
|
+
throw new Error("bad values");
|
|
342
|
+
contextOptions.viewport = { width, height };
|
|
309
343
|
} catch (e) {
|
|
310
344
|
throw new Error('Invalid viewport size format: use "width,height", for example --viewport-size="800,600"');
|
|
311
345
|
}
|
|
312
346
|
}
|
|
313
|
-
|
|
314
|
-
// Geolocation
|
|
315
|
-
|
|
316
347
|
if (options.geolocation) {
|
|
317
348
|
try {
|
|
318
|
-
const [latitude, longitude] = options.geolocation.split(
|
|
349
|
+
const [latitude, longitude] = options.geolocation.split(",").map((n) => parseFloat(n.trim()));
|
|
319
350
|
contextOptions.geolocation = {
|
|
320
351
|
latitude,
|
|
321
352
|
longitude
|
|
@@ -323,94 +354,71 @@ async function launchContext(options, extraOptions) {
|
|
|
323
354
|
} catch (e) {
|
|
324
355
|
throw new Error('Invalid geolocation format, should be "lat,long". For example --geolocation="37.819722,-122.478611"');
|
|
325
356
|
}
|
|
326
|
-
contextOptions.permissions = [
|
|
357
|
+
contextOptions.permissions = ["geolocation"];
|
|
327
358
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
// Timezone
|
|
342
|
-
|
|
343
|
-
if (options.timezone) contextOptions.timezoneId = options.timezone;
|
|
344
|
-
|
|
345
|
-
// Storage
|
|
346
|
-
|
|
347
|
-
if (options.loadStorage) contextOptions.storageState = options.loadStorage;
|
|
348
|
-
if (options.ignoreHttpsErrors) contextOptions.ignoreHTTPSErrors = true;
|
|
349
|
-
|
|
350
|
-
// HAR
|
|
351
|
-
|
|
359
|
+
if (options.userAgent)
|
|
360
|
+
contextOptions.userAgent = options.userAgent;
|
|
361
|
+
if (options.lang)
|
|
362
|
+
contextOptions.locale = options.lang;
|
|
363
|
+
if (options.colorScheme)
|
|
364
|
+
contextOptions.colorScheme = options.colorScheme;
|
|
365
|
+
if (options.timezone)
|
|
366
|
+
contextOptions.timezoneId = options.timezone;
|
|
367
|
+
if (options.loadStorage)
|
|
368
|
+
contextOptions.storageState = options.loadStorage;
|
|
369
|
+
if (options.ignoreHttpsErrors)
|
|
370
|
+
contextOptions.ignoreHTTPSErrors = true;
|
|
352
371
|
if (options.saveHar) {
|
|
353
|
-
contextOptions.recordHar = {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
if (options.saveHarGlob) contextOptions.recordHar.urlFilter = options.saveHarGlob;
|
|
358
|
-
contextOptions.serviceWorkers = 'block';
|
|
372
|
+
contextOptions.recordHar = { path: import_path.default.resolve(process.cwd(), options.saveHar), mode: "minimal" };
|
|
373
|
+
if (options.saveHarGlob)
|
|
374
|
+
contextOptions.recordHar.urlFilter = options.saveHarGlob;
|
|
375
|
+
contextOptions.serviceWorkers = "block";
|
|
359
376
|
}
|
|
360
|
-
|
|
361
|
-
// Close app when the last window closes.
|
|
362
|
-
|
|
363
377
|
const context = await browser.newContext(contextOptions);
|
|
364
378
|
let closingBrowser = false;
|
|
365
379
|
async function closeBrowser() {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (closingBrowser) return;
|
|
380
|
+
if (closingBrowser)
|
|
381
|
+
return;
|
|
369
382
|
closingBrowser = true;
|
|
370
|
-
if (options.saveStorage)
|
|
371
|
-
path: options.saveStorage
|
|
372
|
-
|
|
373
|
-
|
|
383
|
+
if (options.saveStorage)
|
|
384
|
+
await context.storageState({ path: options.saveStorage }).catch((e) => null);
|
|
385
|
+
if (options.saveHar)
|
|
386
|
+
await context.close();
|
|
374
387
|
await browser.close();
|
|
375
388
|
}
|
|
376
|
-
context.on(
|
|
377
|
-
page.on(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
389
|
+
context.on("page", (page) => {
|
|
390
|
+
page.on("dialog", () => {
|
|
391
|
+
});
|
|
392
|
+
page.on("close", () => {
|
|
393
|
+
const hasPage = browser.contexts().some((context2) => context2.pages().length > 0);
|
|
394
|
+
if (hasPage)
|
|
395
|
+
return;
|
|
396
|
+
closeBrowser().catch(() => {
|
|
397
|
+
});
|
|
383
398
|
});
|
|
384
399
|
});
|
|
385
|
-
process.on(
|
|
400
|
+
process.on("SIGINT", async () => {
|
|
386
401
|
await closeBrowser();
|
|
387
|
-
(0,
|
|
402
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(130);
|
|
388
403
|
});
|
|
389
404
|
const timeout = options.timeout ? parseInt(options.timeout, 10) : 0;
|
|
390
405
|
context.setDefaultTimeout(timeout);
|
|
391
406
|
context.setDefaultNavigationTimeout(timeout);
|
|
392
|
-
|
|
393
|
-
// Omit options that we add automatically for presentation purpose.
|
|
394
407
|
delete launchOptions.headless;
|
|
395
408
|
delete launchOptions.executablePath;
|
|
396
409
|
delete launchOptions.handleSIGINT;
|
|
397
410
|
delete contextOptions.deviceScaleFactor;
|
|
398
|
-
return {
|
|
399
|
-
browser,
|
|
400
|
-
browserName: browserType.name(),
|
|
401
|
-
context,
|
|
402
|
-
contextOptions,
|
|
403
|
-
launchOptions
|
|
404
|
-
};
|
|
411
|
+
return { browser, browserName: browserType.name(), context, contextOptions, launchOptions };
|
|
405
412
|
}
|
|
406
413
|
async function openPage(context, url) {
|
|
407
414
|
const page = await context.newPage();
|
|
408
415
|
if (url) {
|
|
409
|
-
if (
|
|
410
|
-
|
|
416
|
+
if (import_fs.default.existsSync(url))
|
|
417
|
+
url = "file://" + import_path.default.resolve(url);
|
|
418
|
+
else if (!url.startsWith("http") && !url.startsWith("file://") && !url.startsWith("about:") && !url.startsWith("data:"))
|
|
419
|
+
url = "http://" + url;
|
|
420
|
+
await page.goto(url).catch((error) => {
|
|
411
421
|
if (process.env.PWTEST_CLI_AUTO_EXIT_WHEN) {
|
|
412
|
-
// Tests with PWTEST_CLI_AUTO_EXIT_WHEN might close page too fast, resulting
|
|
413
|
-
// in a stray navigation aborted error. We should ignore it.
|
|
414
422
|
} else {
|
|
415
423
|
throw error;
|
|
416
424
|
}
|
|
@@ -419,14 +427,7 @@ async function openPage(context, url) {
|
|
|
419
427
|
return page;
|
|
420
428
|
}
|
|
421
429
|
async function open(options, url, language) {
|
|
422
|
-
const {
|
|
423
|
-
context,
|
|
424
|
-
launchOptions,
|
|
425
|
-
contextOptions
|
|
426
|
-
} = await launchContext(options, {
|
|
427
|
-
headless: !!process.env.PWTEST_CLI_HEADLESS,
|
|
428
|
-
executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH
|
|
429
|
-
});
|
|
430
|
+
const { context, launchOptions, contextOptions } = await launchContext(options, { headless: !!process.env.PWTEST_CLI_HEADLESS, executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH });
|
|
430
431
|
await context._enableRecorder({
|
|
431
432
|
language,
|
|
432
433
|
launchOptions,
|
|
@@ -438,33 +439,23 @@ async function open(options, url, language) {
|
|
|
438
439
|
await openPage(context, url);
|
|
439
440
|
}
|
|
440
441
|
async function codegen(options, url) {
|
|
441
|
-
const {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
testIdAttribute: testIdAttributeName
|
|
445
|
-
} = options;
|
|
446
|
-
const tracesDir = _path.default.join(_os.default.tmpdir(), `playwright-recorder-trace-${Date.now()}`);
|
|
447
|
-
const {
|
|
448
|
-
context,
|
|
449
|
-
launchOptions,
|
|
450
|
-
contextOptions
|
|
451
|
-
} = await launchContext(options, {
|
|
442
|
+
const { target: language, output: outputFile, testIdAttribute: testIdAttributeName } = options;
|
|
443
|
+
const tracesDir = import_path.default.join(import_os.default.tmpdir(), `playwright-recorder-trace-${Date.now()}`);
|
|
444
|
+
const { context, launchOptions, contextOptions } = await launchContext(options, {
|
|
452
445
|
headless: !!process.env.PWTEST_CLI_HEADLESS,
|
|
453
446
|
executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH,
|
|
454
447
|
tracesDir
|
|
455
448
|
});
|
|
456
|
-
|
|
457
|
-
path: 'playwright.env'
|
|
458
|
-
});
|
|
449
|
+
import_utilsBundle.dotenv.config({ path: "playwright.env" });
|
|
459
450
|
await context._enableRecorder({
|
|
460
451
|
language,
|
|
461
452
|
launchOptions,
|
|
462
453
|
contextOptions,
|
|
463
454
|
device: options.device,
|
|
464
455
|
saveStorage: options.saveStorage,
|
|
465
|
-
mode:
|
|
456
|
+
mode: "recording",
|
|
466
457
|
testIdAttributeName,
|
|
467
|
-
outputFile: outputFile ?
|
|
458
|
+
outputFile: outputFile ? import_path.default.resolve(outputFile) : void 0,
|
|
468
459
|
handleSIGINT: false
|
|
469
460
|
});
|
|
470
461
|
await openPage(context, url);
|
|
@@ -479,41 +470,24 @@ async function waitForPage(page, captureOptions) {
|
|
|
479
470
|
await page.waitForTimeout(parseInt(captureOptions.waitForTimeout, 10));
|
|
480
471
|
}
|
|
481
472
|
}
|
|
482
|
-
async function screenshot(options, captureOptions, url,
|
|
483
|
-
const {
|
|
484
|
-
|
|
485
|
-
} = await launchContext(options, {
|
|
486
|
-
headless: true
|
|
487
|
-
});
|
|
488
|
-
console.log('Navigating to ' + url);
|
|
473
|
+
async function screenshot(options, captureOptions, url, path2) {
|
|
474
|
+
const { context } = await launchContext(options, { headless: true });
|
|
475
|
+
console.log("Navigating to " + url);
|
|
489
476
|
const page = await openPage(context, url);
|
|
490
477
|
await waitForPage(page, captureOptions);
|
|
491
|
-
console.log(
|
|
492
|
-
await page.screenshot({
|
|
493
|
-
path,
|
|
494
|
-
fullPage: !!captureOptions.fullPage
|
|
495
|
-
});
|
|
496
|
-
// launchContext takes care of closing the browser.
|
|
478
|
+
console.log("Capturing screenshot into " + path2);
|
|
479
|
+
await page.screenshot({ path: path2, fullPage: !!captureOptions.fullPage });
|
|
497
480
|
await page.close();
|
|
498
481
|
}
|
|
499
|
-
async function pdf(options, captureOptions, url,
|
|
500
|
-
if (options.browser !==
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
...options,
|
|
505
|
-
browser: 'chromium'
|
|
506
|
-
}, {
|
|
507
|
-
headless: true
|
|
508
|
-
});
|
|
509
|
-
console.log('Navigating to ' + url);
|
|
482
|
+
async function pdf(options, captureOptions, url, path2) {
|
|
483
|
+
if (options.browser !== "chromium")
|
|
484
|
+
throw new Error("PDF creation is only working with Chromium");
|
|
485
|
+
const { context } = await launchContext({ ...options, browser: "chromium" }, { headless: true });
|
|
486
|
+
console.log("Navigating to " + url);
|
|
510
487
|
const page = await openPage(context, url);
|
|
511
488
|
await waitForPage(page, captureOptions);
|
|
512
|
-
console.log(
|
|
513
|
-
await page.pdf({
|
|
514
|
-
path
|
|
515
|
-
});
|
|
516
|
-
// launchContext takes care of closing the browser.
|
|
489
|
+
console.log("Saving as pdf into " + path2);
|
|
490
|
+
await page.pdf({ path: path2, format: captureOptions.paperFormat });
|
|
517
491
|
await page.close();
|
|
518
492
|
}
|
|
519
493
|
function lookupBrowserType(options) {
|
|
@@ -524,60 +498,70 @@ function lookupBrowserType(options) {
|
|
|
524
498
|
}
|
|
525
499
|
let browserType;
|
|
526
500
|
switch (name) {
|
|
527
|
-
case
|
|
501
|
+
case "chromium":
|
|
528
502
|
browserType = playwright.chromium;
|
|
529
503
|
break;
|
|
530
|
-
case
|
|
504
|
+
case "webkit":
|
|
531
505
|
browserType = playwright.webkit;
|
|
532
506
|
break;
|
|
533
|
-
case
|
|
507
|
+
case "firefox":
|
|
534
508
|
browserType = playwright.firefox;
|
|
535
509
|
break;
|
|
536
|
-
case
|
|
510
|
+
case "cr":
|
|
537
511
|
browserType = playwright.chromium;
|
|
538
512
|
break;
|
|
539
|
-
case
|
|
513
|
+
case "wk":
|
|
540
514
|
browserType = playwright.webkit;
|
|
541
515
|
break;
|
|
542
|
-
case
|
|
516
|
+
case "ff":
|
|
543
517
|
browserType = playwright.firefox;
|
|
544
518
|
break;
|
|
545
519
|
}
|
|
546
|
-
if (browserType)
|
|
547
|
-
|
|
520
|
+
if (browserType)
|
|
521
|
+
return browserType;
|
|
522
|
+
import_utilsBundle.program.help();
|
|
548
523
|
}
|
|
549
524
|
function validateOptions(options) {
|
|
550
525
|
if (options.device && !(options.device in playwright.devices)) {
|
|
551
526
|
const lines = [`Device descriptor not found: '${options.device}', available devices are:`];
|
|
552
|
-
for (const name in playwright.devices)
|
|
553
|
-
|
|
527
|
+
for (const name in playwright.devices)
|
|
528
|
+
lines.push(` "${name}"`);
|
|
529
|
+
throw new Error(lines.join("\n"));
|
|
554
530
|
}
|
|
555
|
-
if (options.colorScheme && ![
|
|
531
|
+
if (options.colorScheme && !["light", "dark"].includes(options.colorScheme))
|
|
532
|
+
throw new Error('Invalid color scheme, should be one of "light", "dark"');
|
|
556
533
|
}
|
|
557
534
|
function logErrorAndExit(e) {
|
|
558
|
-
if (process.env.PWDEBUGIMPL)
|
|
559
|
-
|
|
535
|
+
if (process.env.PWDEBUGIMPL)
|
|
536
|
+
console.error(e);
|
|
537
|
+
else
|
|
538
|
+
console.error(e.name + ": " + e.message);
|
|
539
|
+
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
|
|
560
540
|
}
|
|
561
541
|
function codegenId() {
|
|
562
|
-
return process.env.PW_LANG_NAME ||
|
|
542
|
+
return process.env.PW_LANG_NAME || "playwright-test";
|
|
563
543
|
}
|
|
564
544
|
function commandWithOpenOptions(command, description, options) {
|
|
565
|
-
let result =
|
|
566
|
-
for (const option of options)
|
|
567
|
-
|
|
545
|
+
let result = import_utilsBundle.program.command(command).description(description);
|
|
546
|
+
for (const option of options)
|
|
547
|
+
result = result.option(option[0], ...option.slice(1));
|
|
548
|
+
return result.option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("--block-service-workers", "block service workers").option("--channel <channel>", 'Chromium distribution channel, "chrome", "chrome-beta", "msedge-dev", etc').option("--color-scheme <scheme>", 'emulate preferred color scheme, "light" or "dark"').option("--device <deviceName>", 'emulate device, for example "iPhone 11"').option("--geolocation <coordinates>", 'specify geolocation coordinates, for example "37.819722,-122.478611"').option("--ignore-https-errors", "ignore https errors").option("--load-storage <filename>", "load context storage state from the file, previously saved with --save-storage").option("--lang <language>", 'specify language / locale, for example "en-GB"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--save-har <filename>", "save HAR file with all network activity at the end").option("--save-har-glob <glob pattern>", "filter entries in the HAR by matching url against this glob pattern").option("--save-storage <filename>", "save context storage state at the end, for later use with --load-storage").option("--timezone <time zone>", 'time zone to emulate, for example "Europe/Rome"').option("--timeout <timeout>", "timeout for Playwright actions in milliseconds, no timeout by default").option("--user-agent <ua string>", "specify user agent string").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280, 720"');
|
|
568
549
|
}
|
|
569
550
|
function buildBasePlaywrightCLICommand(cliTargetLang) {
|
|
570
551
|
switch (cliTargetLang) {
|
|
571
|
-
case
|
|
552
|
+
case "python":
|
|
572
553
|
return `playwright`;
|
|
573
|
-
case
|
|
554
|
+
case "java":
|
|
574
555
|
return `mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="...options.."`;
|
|
575
|
-
case
|
|
556
|
+
case "csharp":
|
|
576
557
|
return `pwsh bin/Debug/netX/playwright.ps1`;
|
|
577
|
-
default:
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
558
|
+
default: {
|
|
559
|
+
const packageManagerCommand = (0, import_utils2.getPackageManagerExecCommand)();
|
|
560
|
+
return `${packageManagerCommand} playwright`;
|
|
561
|
+
}
|
|
582
562
|
}
|
|
583
|
-
}
|
|
563
|
+
}
|
|
564
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
565
|
+
0 && (module.exports = {
|
|
566
|
+
program
|
|
567
|
+
});
|