@checkly/playwright-core 1.41.2-beta.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +3 -0
- package/ThirdPartyNotices.txt +1513 -0
- package/bin/PrintDeps.exe +0 -0
- package/bin/README.md +2 -0
- package/bin/install_media_pack.ps1 +5 -0
- package/bin/reinstall_chrome_beta_linux.sh +40 -0
- package/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/bin/reinstall_chrome_beta_win.ps1 +23 -0
- package/bin/reinstall_chrome_stable_linux.sh +40 -0
- package/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/bin/reinstall_chrome_stable_win.ps1 +23 -0
- package/bin/reinstall_msedge_beta_linux.sh +40 -0
- package/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/bin/reinstall_msedge_beta_win.ps1 +22 -0
- package/bin/reinstall_msedge_dev_linux.sh +40 -0
- package/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/bin/reinstall_msedge_dev_win.ps1 +22 -0
- package/bin/reinstall_msedge_stable_linux.sh +40 -0
- package/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/bin/reinstall_msedge_stable_win.ps1 +23 -0
- package/browsers.json +64 -0
- package/cli.js +17 -0
- package/index.d.ts +17 -0
- package/index.js +33 -0
- package/index.mjs +28 -0
- package/lib/androidServerImpl.js +69 -0
- package/lib/browserServerImpl.js +92 -0
- package/lib/cli/driver.js +97 -0
- package/lib/cli/program.js +582 -0
- package/lib/cli/programWithTestStub.js +67 -0
- package/lib/client/accessibility.js +50 -0
- package/lib/client/android.js +473 -0
- package/lib/client/api.js +272 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +145 -0
- package/lib/client/browserContext.js +509 -0
- package/lib/client/browserType.js +233 -0
- package/lib/client/cdpSession.js +53 -0
- package/lib/client/channelOwner.js +229 -0
- package/lib/client/clientHelper.js +57 -0
- package/lib/client/clientInstrumentation.js +40 -0
- package/lib/client/connection.js +327 -0
- package/lib/client/consoleMessage.js +55 -0
- package/lib/client/coverage.js +41 -0
- package/lib/client/dialog.js +57 -0
- package/lib/client/download.js +62 -0
- package/lib/client/electron.js +130 -0
- package/lib/client/elementHandle.js +291 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/events.js +93 -0
- package/lib/client/fetch.js +343 -0
- package/lib/client/fileChooser.js +45 -0
- package/lib/client/frame.js +506 -0
- package/lib/client/harRouter.js +93 -0
- package/lib/client/input.js +111 -0
- package/lib/client/jsHandle.js +123 -0
- package/lib/client/jsonPipe.js +35 -0
- package/lib/client/localUtils.js +35 -0
- package/lib/client/locator.js +432 -0
- package/lib/client/network.js +601 -0
- package/lib/client/page.js +707 -0
- package/lib/client/playwright.js +74 -0
- package/lib/client/selectors.js +67 -0
- package/lib/client/stream.js +54 -0
- package/lib/client/tracing.js +135 -0
- package/lib/client/types.js +24 -0
- package/lib/client/video.js +51 -0
- package/lib/client/waiter.js +158 -0
- package/lib/client/webError.js +37 -0
- package/lib/client/worker.js +71 -0
- package/lib/client/writableStream.js +54 -0
- package/lib/common/socksProxy.js +569 -0
- package/lib/common/timeoutSettings.js +73 -0
- package/lib/common/types.js +5 -0
- package/lib/generated/consoleApiSource.js +7 -0
- package/lib/generated/injectedScriptSource.js +7 -0
- package/lib/generated/recorderSource.js +7 -0
- package/lib/generated/utilityScriptSource.js +7 -0
- package/lib/image_tools/colorUtils.js +98 -0
- package/lib/image_tools/compare.js +108 -0
- package/lib/image_tools/imageChannel.js +70 -0
- package/lib/image_tools/stats.js +102 -0
- package/lib/inProcessFactory.js +54 -0
- package/lib/inprocess.js +20 -0
- package/lib/outofprocess.js +67 -0
- package/lib/protocol/debug.js +27 -0
- package/lib/protocol/serializers.js +172 -0
- package/lib/protocol/transport.js +82 -0
- package/lib/protocol/validator.js +2599 -0
- package/lib/protocol/validatorPrimitives.js +139 -0
- package/lib/remote/playwrightConnection.js +274 -0
- package/lib/remote/playwrightServer.js +110 -0
- package/lib/server/accessibility.js +62 -0
- package/lib/server/android/android.js +441 -0
- package/lib/server/android/backendAdb.js +172 -0
- package/lib/server/artifact.js +104 -0
- package/lib/server/browser.js +129 -0
- package/lib/server/browserContext.js +609 -0
- package/lib/server/browserType.js +300 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +346 -0
- package/lib/server/chromium/chromiumSwitches.js +41 -0
- package/lib/server/chromium/crAccessibility.js +237 -0
- package/lib/server/chromium/crBrowser.js +521 -0
- package/lib/server/chromium/crConnection.js +228 -0
- package/lib/server/chromium/crCoverage.js +246 -0
- package/lib/server/chromium/crDevTools.js +104 -0
- package/lib/server/chromium/crDragDrop.js +144 -0
- package/lib/server/chromium/crExecutionContext.js +156 -0
- package/lib/server/chromium/crInput.js +171 -0
- package/lib/server/chromium/crNetworkManager.js +723 -0
- package/lib/server/chromium/crPage.js +1173 -0
- package/lib/server/chromium/crPdf.js +147 -0
- package/lib/server/chromium/crProtocolHelper.js +131 -0
- package/lib/server/chromium/crServiceWorker.js +115 -0
- package/lib/server/chromium/defaultFontFamilies.js +145 -0
- package/lib/server/chromium/videoRecorder.js +155 -0
- package/lib/server/console.js +59 -0
- package/lib/server/cookieStore.js +112 -0
- package/lib/server/debugController.js +236 -0
- package/lib/server/debugger.js +132 -0
- package/lib/server/deviceDescriptors.js +21 -0
- package/lib/server/deviceDescriptorsSource.json +1549 -0
- package/lib/server/dialog.js +70 -0
- package/lib/server/dispatchers/androidDispatcher.js +193 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +306 -0
- package/lib/server/dispatchers/browserDispatcher.js +170 -0
- package/lib/server/dispatchers/browserTypeDispatcher.js +55 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +48 -0
- package/lib/server/dispatchers/debugControllerDispatcher.js +103 -0
- package/lib/server/dispatchers/dialogDispatcher.js +44 -0
- package/lib/server/dispatchers/dispatcher.js +400 -0
- package/lib/server/dispatchers/electronDispatcher.js +80 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +228 -0
- package/lib/server/dispatchers/frameDispatcher.js +287 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +102 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +61 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +399 -0
- package/lib/server/dispatchers/networkDispatchers.js +221 -0
- package/lib/server/dispatchers/pageDispatcher.js +363 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +105 -0
- package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
- package/lib/server/dispatchers/streamDispatcher.js +62 -0
- package/lib/server/dispatchers/tracingDispatcher.js +54 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +55 -0
- package/lib/server/dom.js +808 -0
- package/lib/server/download.js +53 -0
- package/lib/server/electron/electron.js +254 -0
- package/lib/server/electron/loader.js +57 -0
- package/lib/server/errors.js +68 -0
- package/lib/server/fetch.js +611 -0
- package/lib/server/fileChooser.js +42 -0
- package/lib/server/fileUploadUtils.js +71 -0
- package/lib/server/firefox/ffAccessibility.js +215 -0
- package/lib/server/firefox/ffBrowser.js +447 -0
- package/lib/server/firefox/ffConnection.js +168 -0
- package/lib/server/firefox/ffExecutionContext.js +138 -0
- package/lib/server/firefox/ffInput.js +150 -0
- package/lib/server/firefox/ffNetworkManager.js +231 -0
- package/lib/server/firefox/ffPage.js +558 -0
- package/lib/server/firefox/firefox.js +91 -0
- package/lib/server/formData.js +75 -0
- package/lib/server/frameSelectors.js +171 -0
- package/lib/server/frames.js +1597 -0
- package/lib/server/har/harRecorder.js +139 -0
- package/lib/server/har/harTracer.js +539 -0
- package/lib/server/helper.js +103 -0
- package/lib/server/index.js +96 -0
- package/lib/server/input.js +301 -0
- package/lib/server/instrumentation.js +74 -0
- package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
- package/lib/server/javascript.js +305 -0
- package/lib/server/launchApp.js +90 -0
- package/lib/server/macEditingCommands.js +139 -0
- package/lib/server/network.js +607 -0
- package/lib/server/page.js +793 -0
- package/lib/server/pipeTransport.js +85 -0
- package/lib/server/playwright.js +82 -0
- package/lib/server/progress.js +102 -0
- package/lib/server/protocolError.js +49 -0
- package/lib/server/recorder/codeGenerator.js +153 -0
- package/lib/server/recorder/csharp.js +310 -0
- package/lib/server/recorder/java.js +216 -0
- package/lib/server/recorder/javascript.js +229 -0
- package/lib/server/recorder/jsonl.js +47 -0
- package/lib/server/recorder/language.js +44 -0
- package/lib/server/recorder/python.js +275 -0
- package/lib/server/recorder/recorderActions.js +5 -0
- package/lib/server/recorder/recorderApp.js +181 -0
- package/lib/server/recorder/recorderUtils.js +48 -0
- package/lib/server/recorder/utils.js +45 -0
- package/lib/server/recorder.js +700 -0
- package/lib/server/registry/browserFetcher.js +168 -0
- package/lib/server/registry/dependencies.js +322 -0
- package/lib/server/registry/index.js +925 -0
- package/lib/server/registry/nativeDeps.js +383 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +138 -0
- package/lib/server/screenshotter.js +354 -0
- package/lib/server/selectors.js +73 -0
- package/lib/server/socksInterceptor.js +100 -0
- package/lib/server/trace/recorder/snapshotter.js +168 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +493 -0
- package/lib/server/trace/recorder/tracing.js +552 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +93 -0
- package/lib/server/trace/viewer/traceViewer.js +229 -0
- package/lib/server/transport.js +191 -0
- package/lib/server/types.js +24 -0
- package/lib/server/usKeyboardLayout.js +555 -0
- package/lib/server/webkit/webkit.js +87 -0
- package/lib/server/webkit/wkAccessibility.js +194 -0
- package/lib/server/webkit/wkBrowser.js +328 -0
- package/lib/server/webkit/wkConnection.js +173 -0
- package/lib/server/webkit/wkExecutionContext.js +146 -0
- package/lib/server/webkit/wkInput.js +169 -0
- package/lib/server/webkit/wkInterceptableRequest.js +158 -0
- package/lib/server/webkit/wkPage.js +1198 -0
- package/lib/server/webkit/wkProvisionalPage.js +59 -0
- package/lib/server/webkit/wkWorkers.js +104 -0
- package/lib/third_party/diff_match_patch.js +2222 -0
- package/lib/third_party/pixelmatch.js +255 -0
- package/lib/utils/ascii.js +31 -0
- package/lib/utils/comparators.js +171 -0
- package/lib/utils/crypto.js +33 -0
- package/lib/utils/debug.js +46 -0
- package/lib/utils/debugLogger.js +89 -0
- package/lib/utils/env.js +47 -0
- package/lib/utils/eventsHelper.js +38 -0
- package/lib/utils/fileUtils.js +66 -0
- package/lib/utils/glob.js +83 -0
- package/lib/utils/happy-eyeballs.js +154 -0
- package/lib/utils/headers.js +52 -0
- package/lib/utils/hostPlatform.js +124 -0
- package/lib/utils/httpServer.js +195 -0
- package/lib/utils/index.js +324 -0
- package/lib/utils/isomorphic/cssParser.js +250 -0
- package/lib/utils/isomorphic/cssTokenizer.js +979 -0
- package/lib/utils/isomorphic/locatorGenerators.js +651 -0
- package/lib/utils/isomorphic/locatorParser.js +179 -0
- package/lib/utils/isomorphic/locatorUtils.js +62 -0
- package/lib/utils/isomorphic/selectorParser.js +397 -0
- package/lib/utils/isomorphic/stringUtils.js +107 -0
- package/lib/utils/isomorphic/traceUtils.js +39 -0
- package/lib/utils/linuxUtils.js +78 -0
- package/lib/utils/manualPromise.js +109 -0
- package/lib/utils/mimeType.js +29 -0
- package/lib/utils/multimap.js +75 -0
- package/lib/utils/network.js +189 -0
- package/lib/utils/processLauncher.js +248 -0
- package/lib/utils/profiler.js +53 -0
- package/lib/utils/rtti.js +41 -0
- package/lib/utils/semaphore.js +51 -0
- package/lib/utils/spawnAsync.js +45 -0
- package/lib/utils/stackTrace.js +123 -0
- package/lib/utils/task.js +58 -0
- package/lib/utils/time.js +37 -0
- package/lib/utils/timeoutRunner.js +131 -0
- package/lib/utils/traceUtils.js +44 -0
- package/lib/utils/userAgent.js +105 -0
- package/lib/utils/wsServer.js +125 -0
- package/lib/utils/zipFile.js +75 -0
- package/lib/utils/zones.js +99 -0
- package/lib/utilsBundle.js +81 -0
- package/lib/utilsBundleImpl/index.js +51 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +66 -0
- package/lib/vite/recorder/assets/codeMirrorModule-Hs9-1ZG4.css +1 -0
- package/lib/vite/recorder/assets/codeMirrorModule-I9ks4y7D.js +24 -0
- package/lib/vite/recorder/assets/codicon-zGuYmc9o.ttf +0 -0
- package/lib/vite/recorder/assets/index-ljsTwXtJ.css +1 -0
- package/lib/vite/recorder/assets/index-yg8ypzl6.js +47 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-GluP1cQ1.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-fqJB1XDu.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-y3M3aAqy.js +24 -0
- package/lib/vite/traceViewer/assets/wsPort-Rvwd4WC-.js +69 -0
- package/lib/vite/traceViewer/assets/wsPort-dlD7vDkY.js +69 -0
- package/lib/vite/traceViewer/assets/wsPort-qOE2NWrO.js +69 -0
- package/lib/vite/traceViewer/assets/xtermModule-Yt6xwiJ_.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.Hs9-1ZG4.css +1 -0
- package/lib/vite/traceViewer/codicon.zGuYmc9o.ttf +0 -0
- package/lib/vite/traceViewer/index.-g_5lMbJ.css +1 -0
- package/lib/vite/traceViewer/index.4X7zDysg.js +2 -0
- package/lib/vite/traceViewer/index.HkJgzlGy.js +2 -0
- package/lib/vite/traceViewer/index.html +26 -0
- package/lib/vite/traceViewer/index.kRjx5sAJ.js +2 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +4 -0
- package/lib/vite/traceViewer/uiMode.1Wcp_Kto.js +10 -0
- package/lib/vite/traceViewer/uiMode.GTNzARcV.js +10 -0
- package/lib/vite/traceViewer/uiMode.html +17 -0
- package/lib/vite/traceViewer/uiMode.pWy0Re7G.css +1 -0
- package/lib/vite/traceViewer/uiMode.zV-7Lf9v.js +10 -0
- package/lib/vite/traceViewer/wsPort.kSgQKQ0y.css +1 -0
- package/lib/vite/traceViewer/xtermModule.0lwXJFHT.css +32 -0
- package/lib/zipBundle.js +25 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +43 -0
- package/types/protocol.d.ts +20304 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +20626 -0
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Recorder = void 0;
|
|
7
|
+
var fs = _interopRequireWildcard(require("fs"));
|
|
8
|
+
var _codeGenerator = require("./recorder/codeGenerator");
|
|
9
|
+
var _utils = require("./recorder/utils");
|
|
10
|
+
var _page = require("./page");
|
|
11
|
+
var _frames = require("./frames");
|
|
12
|
+
var _browserContext = require("./browserContext");
|
|
13
|
+
var _java = require("./recorder/java");
|
|
14
|
+
var _javascript = require("./recorder/javascript");
|
|
15
|
+
var _jsonl = require("./recorder/jsonl");
|
|
16
|
+
var _csharp = require("./recorder/csharp");
|
|
17
|
+
var _python = require("./recorder/python");
|
|
18
|
+
var recorderSource = _interopRequireWildcard(require("../generated/recorderSource"));
|
|
19
|
+
var consoleApiSource = _interopRequireWildcard(require("../generated/consoleApiSource"));
|
|
20
|
+
var _recorderApp = require("./recorder/recorderApp");
|
|
21
|
+
var _utils2 = require("../utils");
|
|
22
|
+
var _recorderUtils = require("./recorder/recorderUtils");
|
|
23
|
+
var _debugger = require("./debugger");
|
|
24
|
+
var _events = require("events");
|
|
25
|
+
var _timeoutRunner = require("../utils/timeoutRunner");
|
|
26
|
+
var _locatorParser = require("../utils/isomorphic/locatorParser");
|
|
27
|
+
var _stringUtils = require("../utils/isomorphic/stringUtils");
|
|
28
|
+
var _eventsHelper = require("./../utils/eventsHelper");
|
|
29
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
30
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
31
|
+
/**
|
|
32
|
+
* Copyright (c) Microsoft Corporation.
|
|
33
|
+
*
|
|
34
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
35
|
+
* you may not use this file except in compliance with the License.
|
|
36
|
+
* You may obtain a copy of the License at
|
|
37
|
+
*
|
|
38
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
39
|
+
*
|
|
40
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
41
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
43
|
+
* See the License for the specific language governing permissions and
|
|
44
|
+
* limitations under the License.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
const recorderSymbol = Symbol('recorderSymbol');
|
|
48
|
+
class Recorder {
|
|
49
|
+
static setAppFactory(recorderAppFactory) {
|
|
50
|
+
Recorder.recorderAppFactory = recorderAppFactory;
|
|
51
|
+
}
|
|
52
|
+
static showInspector(context) {
|
|
53
|
+
const params = {};
|
|
54
|
+
if ((0, _utils2.isUnderTest)()) params.language = process.env.TEST_INSPECTOR_LANGUAGE;
|
|
55
|
+
Recorder.show(context, params).catch(() => {});
|
|
56
|
+
}
|
|
57
|
+
static show(context, params = {}) {
|
|
58
|
+
let recorderPromise = context[recorderSymbol];
|
|
59
|
+
if (!recorderPromise) {
|
|
60
|
+
const recorder = new Recorder(context, params);
|
|
61
|
+
recorderPromise = recorder.install().then(() => recorder);
|
|
62
|
+
context[recorderSymbol] = recorderPromise;
|
|
63
|
+
}
|
|
64
|
+
return recorderPromise;
|
|
65
|
+
}
|
|
66
|
+
constructor(context, params) {
|
|
67
|
+
this._context = void 0;
|
|
68
|
+
this._mode = void 0;
|
|
69
|
+
this._highlightedSelector = '';
|
|
70
|
+
this._overlayState = {
|
|
71
|
+
offsetX: 0
|
|
72
|
+
};
|
|
73
|
+
this._recorderApp = null;
|
|
74
|
+
this._currentCallsMetadata = new Map();
|
|
75
|
+
this._recorderSources = [];
|
|
76
|
+
this._userSources = new Map();
|
|
77
|
+
this._debugger = void 0;
|
|
78
|
+
this._contextRecorder = void 0;
|
|
79
|
+
this._handleSIGINT = void 0;
|
|
80
|
+
this._omitCallTracking = false;
|
|
81
|
+
this._currentLanguage = void 0;
|
|
82
|
+
this._mode = params.mode || 'none';
|
|
83
|
+
this._contextRecorder = new ContextRecorder(context, params);
|
|
84
|
+
this._context = context;
|
|
85
|
+
this._omitCallTracking = !!params.omitCallTracking;
|
|
86
|
+
this._debugger = context.debugger();
|
|
87
|
+
this._handleSIGINT = params.handleSIGINT;
|
|
88
|
+
context.instrumentation.addListener(this, context);
|
|
89
|
+
this._currentLanguage = this._contextRecorder.languageName();
|
|
90
|
+
if ((0, _utils2.isUnderTest)()) {
|
|
91
|
+
// Most of our tests put elements at the top left, so get out of the way.
|
|
92
|
+
this._overlayState.offsetX = 200;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
static async defaultRecorderAppFactory(recorder) {
|
|
96
|
+
if (process.env.PW_CODEGEN_NO_INSPECTOR) return new _recorderApp.EmptyRecorderApp();
|
|
97
|
+
return await _recorderApp.RecorderApp.open(recorder, recorder._context, recorder._handleSIGINT);
|
|
98
|
+
}
|
|
99
|
+
async install() {
|
|
100
|
+
const recorderApp = await (Recorder.recorderAppFactory || Recorder.defaultRecorderAppFactory)(this);
|
|
101
|
+
this._recorderApp = recorderApp;
|
|
102
|
+
recorderApp.once('close', () => {
|
|
103
|
+
this._debugger.resume(false);
|
|
104
|
+
this._recorderApp = null;
|
|
105
|
+
});
|
|
106
|
+
recorderApp.on('event', data => {
|
|
107
|
+
if (data.event === 'setMode') {
|
|
108
|
+
this.setMode(data.params.mode);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (data.event === 'selectorUpdated') {
|
|
112
|
+
this.setHighlightedSelector(this._currentLanguage, data.params.selector);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (data.event === 'step') {
|
|
116
|
+
this._debugger.resume(true);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (data.event === 'fileChanged') {
|
|
120
|
+
this._currentLanguage = this._contextRecorder.languageName(data.params.file);
|
|
121
|
+
this._refreshOverlay();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (data.event === 'resume') {
|
|
125
|
+
this._debugger.resume(false);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (data.event === 'pause') {
|
|
129
|
+
this._debugger.pauseOnNextStatement();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (data.event === 'clear') {
|
|
133
|
+
this._contextRecorder.clearScript();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
await Promise.all([recorderApp.setMode(this._mode), recorderApp.setPaused(this._debugger.isPaused()), this._pushAllSources()]);
|
|
138
|
+
this._context.once(_browserContext.BrowserContext.Events.Close, () => {
|
|
139
|
+
this._contextRecorder.dispose();
|
|
140
|
+
this._context.instrumentation.removeListener(this);
|
|
141
|
+
recorderApp.close().catch(() => {});
|
|
142
|
+
});
|
|
143
|
+
this._contextRecorder.on(ContextRecorder.Events.Change, data => {
|
|
144
|
+
var _this$_recorderApp;
|
|
145
|
+
this._recorderSources = data.sources;
|
|
146
|
+
this._pushAllSources();
|
|
147
|
+
(_this$_recorderApp = this._recorderApp) === null || _this$_recorderApp === void 0 || _this$_recorderApp.setFileIfNeeded(data.primaryFileName);
|
|
148
|
+
});
|
|
149
|
+
await this._context.exposeBinding('__pw_recorderState', false, source => {
|
|
150
|
+
let actionSelector = '';
|
|
151
|
+
let actionPoint;
|
|
152
|
+
const hasActiveScreenshotCommand = [...this._currentCallsMetadata.keys()].some(isScreenshotCommand);
|
|
153
|
+
if (!hasActiveScreenshotCommand) {
|
|
154
|
+
actionSelector = this._highlightedSelector;
|
|
155
|
+
for (const [metadata, sdkObject] of this._currentCallsMetadata) {
|
|
156
|
+
if (source.page === sdkObject.attribution.page) {
|
|
157
|
+
actionPoint = metadata.point || actionPoint;
|
|
158
|
+
actionSelector = actionSelector || metadata.params.selector;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const uiState = {
|
|
163
|
+
mode: this._mode,
|
|
164
|
+
actionPoint,
|
|
165
|
+
actionSelector,
|
|
166
|
+
language: this._currentLanguage,
|
|
167
|
+
testIdAttributeName: this._contextRecorder.testIdAttributeName(),
|
|
168
|
+
overlay: this._overlayState
|
|
169
|
+
};
|
|
170
|
+
return uiState;
|
|
171
|
+
});
|
|
172
|
+
await this._context.exposeBinding('__pw_recorderSetSelector', false, async ({
|
|
173
|
+
frame
|
|
174
|
+
}, selector) => {
|
|
175
|
+
var _this$_recorderApp2;
|
|
176
|
+
const selectorPromises = [];
|
|
177
|
+
let currentFrame = frame;
|
|
178
|
+
while (currentFrame) {
|
|
179
|
+
selectorPromises.push(findFrameSelector(currentFrame));
|
|
180
|
+
currentFrame = currentFrame.parentFrame();
|
|
181
|
+
}
|
|
182
|
+
const fullSelector = (await Promise.all(selectorPromises)).filter(Boolean);
|
|
183
|
+
fullSelector.push(selector);
|
|
184
|
+
await ((_this$_recorderApp2 = this._recorderApp) === null || _this$_recorderApp2 === void 0 ? void 0 : _this$_recorderApp2.setSelector(fullSelector.join(' >> internal:control=enter-frame >> '), true));
|
|
185
|
+
});
|
|
186
|
+
await this._context.exposeBinding('__pw_recorderSetMode', false, async ({
|
|
187
|
+
frame
|
|
188
|
+
}, mode) => {
|
|
189
|
+
if (frame.parentFrame()) return;
|
|
190
|
+
this.setMode(mode);
|
|
191
|
+
});
|
|
192
|
+
await this._context.exposeBinding('__pw_recorderSetOverlayState', false, async ({
|
|
193
|
+
frame
|
|
194
|
+
}, state) => {
|
|
195
|
+
if (frame.parentFrame()) return;
|
|
196
|
+
this._overlayState = state;
|
|
197
|
+
});
|
|
198
|
+
await this._context.exposeBinding('__pw_resume', false, () => {
|
|
199
|
+
this._debugger.resume(false);
|
|
200
|
+
});
|
|
201
|
+
await this._context.extendInjectedScript(consoleApiSource.source);
|
|
202
|
+
await this._contextRecorder.install();
|
|
203
|
+
if (this._debugger.isPaused()) this._pausedStateChanged();
|
|
204
|
+
this._debugger.on(_debugger.Debugger.Events.PausedStateChanged, () => this._pausedStateChanged());
|
|
205
|
+
this._context.recorderAppForTest = recorderApp;
|
|
206
|
+
}
|
|
207
|
+
_pausedStateChanged() {
|
|
208
|
+
var _this$_recorderApp3;
|
|
209
|
+
// If we are called upon page.pause, we don't have metadatas, populate them.
|
|
210
|
+
for (const {
|
|
211
|
+
metadata,
|
|
212
|
+
sdkObject
|
|
213
|
+
} of this._debugger.pausedDetails()) {
|
|
214
|
+
if (!this._currentCallsMetadata.has(metadata)) this.onBeforeCall(sdkObject, metadata);
|
|
215
|
+
}
|
|
216
|
+
(_this$_recorderApp3 = this._recorderApp) === null || _this$_recorderApp3 === void 0 || _this$_recorderApp3.setPaused(this._debugger.isPaused());
|
|
217
|
+
this._updateUserSources();
|
|
218
|
+
this.updateCallLog([...this._currentCallsMetadata.keys()]);
|
|
219
|
+
}
|
|
220
|
+
setMode(mode) {
|
|
221
|
+
var _this$_recorderApp4;
|
|
222
|
+
if (this._mode === mode) return;
|
|
223
|
+
this._highlightedSelector = '';
|
|
224
|
+
this._mode = mode;
|
|
225
|
+
(_this$_recorderApp4 = this._recorderApp) === null || _this$_recorderApp4 === void 0 || _this$_recorderApp4.setMode(this._mode);
|
|
226
|
+
this._contextRecorder.setEnabled(this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue');
|
|
227
|
+
this._debugger.setMuted(this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue');
|
|
228
|
+
if (this._mode !== 'none' && this._mode !== 'standby' && this._context.pages().length === 1) this._context.pages()[0].bringToFront().catch(() => {});
|
|
229
|
+
this._refreshOverlay();
|
|
230
|
+
}
|
|
231
|
+
resume() {
|
|
232
|
+
this._debugger.resume(false);
|
|
233
|
+
}
|
|
234
|
+
mode() {
|
|
235
|
+
return this._mode;
|
|
236
|
+
}
|
|
237
|
+
setHighlightedSelector(language, selector) {
|
|
238
|
+
this._highlightedSelector = (0, _locatorParser.locatorOrSelectorAsSelector)(language, selector, this._context.selectors().testIdAttributeName());
|
|
239
|
+
this._refreshOverlay();
|
|
240
|
+
}
|
|
241
|
+
hideHighlightedSelector() {
|
|
242
|
+
this._highlightedSelector = '';
|
|
243
|
+
this._refreshOverlay();
|
|
244
|
+
}
|
|
245
|
+
setOutput(codegenId, outputFile) {
|
|
246
|
+
this._contextRecorder.setOutput(codegenId, outputFile);
|
|
247
|
+
}
|
|
248
|
+
_refreshOverlay() {
|
|
249
|
+
for (const page of this._context.pages()) page.mainFrame().evaluateExpression('window.__pw_refreshOverlay()').catch(() => {});
|
|
250
|
+
}
|
|
251
|
+
async onBeforeCall(sdkObject, metadata) {
|
|
252
|
+
if (this._omitCallTracking || this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue') return;
|
|
253
|
+
this._currentCallsMetadata.set(metadata, sdkObject);
|
|
254
|
+
this._updateUserSources();
|
|
255
|
+
this.updateCallLog([metadata]);
|
|
256
|
+
if (isScreenshotCommand(metadata)) {
|
|
257
|
+
this.hideHighlightedSelector();
|
|
258
|
+
} else if (metadata.params && metadata.params.selector) {
|
|
259
|
+
var _this$_recorderApp5;
|
|
260
|
+
this._highlightedSelector = metadata.params.selector;
|
|
261
|
+
(_this$_recorderApp5 = this._recorderApp) === null || _this$_recorderApp5 === void 0 || _this$_recorderApp5.setSelector(this._highlightedSelector).catch(() => {});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async onAfterCall(sdkObject, metadata) {
|
|
265
|
+
if (this._omitCallTracking || this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue') return;
|
|
266
|
+
if (!metadata.error) this._currentCallsMetadata.delete(metadata);
|
|
267
|
+
this._updateUserSources();
|
|
268
|
+
this.updateCallLog([metadata]);
|
|
269
|
+
}
|
|
270
|
+
_updateUserSources() {
|
|
271
|
+
var _this$_recorderApp6;
|
|
272
|
+
// Remove old decorations.
|
|
273
|
+
for (const source of this._userSources.values()) {
|
|
274
|
+
source.highlight = [];
|
|
275
|
+
source.revealLine = undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Apply new decorations.
|
|
279
|
+
let fileToSelect = undefined;
|
|
280
|
+
for (const metadata of this._currentCallsMetadata.keys()) {
|
|
281
|
+
if (!metadata.location) continue;
|
|
282
|
+
const {
|
|
283
|
+
file,
|
|
284
|
+
line
|
|
285
|
+
} = metadata.location;
|
|
286
|
+
let source = this._userSources.get(file);
|
|
287
|
+
if (!source) {
|
|
288
|
+
source = {
|
|
289
|
+
isRecorded: false,
|
|
290
|
+
label: file,
|
|
291
|
+
id: file,
|
|
292
|
+
text: this._readSource(file),
|
|
293
|
+
highlight: [],
|
|
294
|
+
language: languageForFile(file)
|
|
295
|
+
};
|
|
296
|
+
this._userSources.set(file, source);
|
|
297
|
+
}
|
|
298
|
+
if (line) {
|
|
299
|
+
const paused = this._debugger.isPaused(metadata);
|
|
300
|
+
source.highlight.push({
|
|
301
|
+
line,
|
|
302
|
+
type: metadata.error ? 'error' : paused ? 'paused' : 'running'
|
|
303
|
+
});
|
|
304
|
+
source.revealLine = line;
|
|
305
|
+
fileToSelect = source.id;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
this._pushAllSources();
|
|
309
|
+
if (fileToSelect) (_this$_recorderApp6 = this._recorderApp) === null || _this$_recorderApp6 === void 0 || _this$_recorderApp6.setFileIfNeeded(fileToSelect);
|
|
310
|
+
}
|
|
311
|
+
_pushAllSources() {
|
|
312
|
+
var _this$_recorderApp7;
|
|
313
|
+
(_this$_recorderApp7 = this._recorderApp) === null || _this$_recorderApp7 === void 0 || _this$_recorderApp7.setSources([...this._recorderSources, ...this._userSources.values()]);
|
|
314
|
+
}
|
|
315
|
+
async onBeforeInputAction(sdkObject, metadata) {}
|
|
316
|
+
async onCallLog(sdkObject, metadata, logName, message) {
|
|
317
|
+
this.updateCallLog([metadata]);
|
|
318
|
+
}
|
|
319
|
+
updateCallLog(metadatas) {
|
|
320
|
+
var _this$_recorderApp8;
|
|
321
|
+
if (this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue') return;
|
|
322
|
+
const logs = [];
|
|
323
|
+
for (const metadata of metadatas) {
|
|
324
|
+
if (!metadata.method || metadata.internal) continue;
|
|
325
|
+
let status = 'done';
|
|
326
|
+
if (this._currentCallsMetadata.has(metadata)) status = 'in-progress';
|
|
327
|
+
if (this._debugger.isPaused(metadata)) status = 'paused';
|
|
328
|
+
logs.push((0, _recorderUtils.metadataToCallLog)(metadata, status));
|
|
329
|
+
}
|
|
330
|
+
(_this$_recorderApp8 = this._recorderApp) === null || _this$_recorderApp8 === void 0 || _this$_recorderApp8.updateCallLogs(logs);
|
|
331
|
+
}
|
|
332
|
+
_readSource(fileName) {
|
|
333
|
+
try {
|
|
334
|
+
return fs.readFileSync(fileName, 'utf-8');
|
|
335
|
+
} catch (e) {
|
|
336
|
+
return '// No source available';
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.Recorder = Recorder;
|
|
341
|
+
Recorder.recorderAppFactory = void 0;
|
|
342
|
+
class ContextRecorder extends _events.EventEmitter {
|
|
343
|
+
constructor(context, params) {
|
|
344
|
+
super();
|
|
345
|
+
this._generator = void 0;
|
|
346
|
+
this._pageAliases = new Map();
|
|
347
|
+
this._lastPopupOrdinal = 0;
|
|
348
|
+
this._lastDialogOrdinal = -1;
|
|
349
|
+
this._lastDownloadOrdinal = -1;
|
|
350
|
+
this._timers = new Set();
|
|
351
|
+
this._context = void 0;
|
|
352
|
+
this._params = void 0;
|
|
353
|
+
this._recorderSources = void 0;
|
|
354
|
+
this._throttledOutputFile = null;
|
|
355
|
+
this._orderedLanguages = [];
|
|
356
|
+
this._listeners = [];
|
|
357
|
+
this._context = context;
|
|
358
|
+
this._params = params;
|
|
359
|
+
this._recorderSources = [];
|
|
360
|
+
const language = params.language || context.attribution.playwright.options.sdkLanguage;
|
|
361
|
+
this.setOutput(language, params.outputFile);
|
|
362
|
+
const generator = new _codeGenerator.CodeGenerator(context._browser.options.name, params.mode === 'recording', params.launchOptions || {}, params.contextOptions || {}, params.device, params.saveStorage);
|
|
363
|
+
generator.on('change', () => {
|
|
364
|
+
this._recorderSources = [];
|
|
365
|
+
for (const languageGenerator of this._orderedLanguages) {
|
|
366
|
+
var _this$_throttledOutpu;
|
|
367
|
+
const {
|
|
368
|
+
header,
|
|
369
|
+
footer,
|
|
370
|
+
actions,
|
|
371
|
+
text
|
|
372
|
+
} = generator.generateStructure(languageGenerator);
|
|
373
|
+
const source = {
|
|
374
|
+
isRecorded: true,
|
|
375
|
+
label: languageGenerator.name,
|
|
376
|
+
group: languageGenerator.groupName,
|
|
377
|
+
id: languageGenerator.id,
|
|
378
|
+
text,
|
|
379
|
+
header,
|
|
380
|
+
footer,
|
|
381
|
+
actions,
|
|
382
|
+
language: languageGenerator.highlighter,
|
|
383
|
+
highlight: []
|
|
384
|
+
};
|
|
385
|
+
source.revealLine = text.split('\n').length - 1;
|
|
386
|
+
this._recorderSources.push(source);
|
|
387
|
+
if (languageGenerator === this._orderedLanguages[0]) (_this$_throttledOutpu = this._throttledOutputFile) === null || _this$_throttledOutpu === void 0 || _this$_throttledOutpu.setContent(source.text);
|
|
388
|
+
}
|
|
389
|
+
this.emit(ContextRecorder.Events.Change, {
|
|
390
|
+
sources: this._recorderSources,
|
|
391
|
+
primaryFileName: this._orderedLanguages[0].id
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
context.on(_browserContext.BrowserContext.Events.BeforeClose, () => {
|
|
395
|
+
var _this$_throttledOutpu2;
|
|
396
|
+
(_this$_throttledOutpu2 = this._throttledOutputFile) === null || _this$_throttledOutpu2 === void 0 || _this$_throttledOutpu2.flush();
|
|
397
|
+
});
|
|
398
|
+
this._listeners.push(_eventsHelper.eventsHelper.addEventListener(process, 'exit', () => {
|
|
399
|
+
var _this$_throttledOutpu3;
|
|
400
|
+
(_this$_throttledOutpu3 = this._throttledOutputFile) === null || _this$_throttledOutpu3 === void 0 || _this$_throttledOutpu3.flush();
|
|
401
|
+
}));
|
|
402
|
+
this._generator = generator;
|
|
403
|
+
}
|
|
404
|
+
setOutput(codegenId, outputFile) {
|
|
405
|
+
var _this$_generator;
|
|
406
|
+
const languages = new Set([new _java.JavaLanguageGenerator(), new _javascript.JavaScriptLanguageGenerator( /* isPlaywrightTest */false), new _javascript.JavaScriptLanguageGenerator( /* isPlaywrightTest */true), new _python.PythonLanguageGenerator( /* isAsync */false, /* isPytest */true), new _python.PythonLanguageGenerator( /* isAsync */false, /* isPytest */false), new _python.PythonLanguageGenerator( /* isAsync */true, /* isPytest */false), new _csharp.CSharpLanguageGenerator('mstest'), new _csharp.CSharpLanguageGenerator('nunit'), new _csharp.CSharpLanguageGenerator('library'), new _jsonl.JsonlLanguageGenerator()]);
|
|
407
|
+
const primaryLanguage = [...languages].find(l => l.id === codegenId);
|
|
408
|
+
if (!primaryLanguage) throw new Error(`\n===============================\nUnsupported language: '${codegenId}'\n===============================\n`);
|
|
409
|
+
languages.delete(primaryLanguage);
|
|
410
|
+
this._orderedLanguages = [primaryLanguage, ...languages];
|
|
411
|
+
this._throttledOutputFile = outputFile ? new ThrottledFile(outputFile) : null;
|
|
412
|
+
(_this$_generator = this._generator) === null || _this$_generator === void 0 || _this$_generator.restart();
|
|
413
|
+
}
|
|
414
|
+
languageName(id) {
|
|
415
|
+
for (const lang of this._orderedLanguages) {
|
|
416
|
+
if (!id || lang.id === id) return lang.highlighter;
|
|
417
|
+
}
|
|
418
|
+
return 'javascript';
|
|
419
|
+
}
|
|
420
|
+
async install() {
|
|
421
|
+
this._context.on(_browserContext.BrowserContext.Events.Page, page => this._onPage(page));
|
|
422
|
+
for (const page of this._context.pages()) this._onPage(page);
|
|
423
|
+
this._context.on(_browserContext.BrowserContext.Events.Dialog, dialog => this._onDialog(dialog.page()));
|
|
424
|
+
|
|
425
|
+
// Input actions that potentially lead to navigation are intercepted on the page and are
|
|
426
|
+
// performed by the Playwright.
|
|
427
|
+
await this._context.exposeBinding('__pw_recorderPerformAction', false, (source, action) => this._performAction(source.frame, action));
|
|
428
|
+
|
|
429
|
+
// Other non-essential actions are simply being recorded.
|
|
430
|
+
await this._context.exposeBinding('__pw_recorderRecordAction', false, (source, action) => this._recordAction(source.frame, action));
|
|
431
|
+
await this._context.extendInjectedScript(recorderSource.source);
|
|
432
|
+
}
|
|
433
|
+
setEnabled(enabled) {
|
|
434
|
+
this._generator.setEnabled(enabled);
|
|
435
|
+
}
|
|
436
|
+
dispose() {
|
|
437
|
+
for (const timer of this._timers) clearTimeout(timer);
|
|
438
|
+
this._timers.clear();
|
|
439
|
+
_eventsHelper.eventsHelper.removeEventListeners(this._listeners);
|
|
440
|
+
}
|
|
441
|
+
async _onPage(page) {
|
|
442
|
+
// First page is called page, others are called popup1, popup2, etc.
|
|
443
|
+
const frame = page.mainFrame();
|
|
444
|
+
page.on('close', () => {
|
|
445
|
+
this._generator.addAction({
|
|
446
|
+
frame: this._describeMainFrame(page),
|
|
447
|
+
committed: true,
|
|
448
|
+
action: {
|
|
449
|
+
name: 'closePage',
|
|
450
|
+
signals: []
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
this._pageAliases.delete(page);
|
|
454
|
+
});
|
|
455
|
+
frame.on(_frames.Frame.Events.InternalNavigation, event => {
|
|
456
|
+
if (event.isPublic) this._onFrameNavigated(frame, page);
|
|
457
|
+
});
|
|
458
|
+
page.on(_page.Page.Events.Download, () => this._onDownload(page));
|
|
459
|
+
const suffix = this._pageAliases.size ? String(++this._lastPopupOrdinal) : '';
|
|
460
|
+
const pageAlias = 'page' + suffix;
|
|
461
|
+
this._pageAliases.set(page, pageAlias);
|
|
462
|
+
if (page.opener()) {
|
|
463
|
+
this._onPopup(page.opener(), page);
|
|
464
|
+
} else {
|
|
465
|
+
this._generator.addAction({
|
|
466
|
+
frame: this._describeMainFrame(page),
|
|
467
|
+
committed: true,
|
|
468
|
+
action: {
|
|
469
|
+
name: 'openPage',
|
|
470
|
+
url: page.mainFrame().url(),
|
|
471
|
+
signals: []
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
clearScript() {
|
|
477
|
+
this._generator.restart();
|
|
478
|
+
if (this._params.mode === 'recording') {
|
|
479
|
+
for (const page of this._context.pages()) this._onFrameNavigated(page.mainFrame(), page);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
_describeMainFrame(page) {
|
|
483
|
+
return {
|
|
484
|
+
pageAlias: this._pageAliases.get(page),
|
|
485
|
+
isMainFrame: true
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
async _describeFrame(frame) {
|
|
489
|
+
const page = frame._page;
|
|
490
|
+
const pageAlias = this._pageAliases.get(page);
|
|
491
|
+
const chain = [];
|
|
492
|
+
for (let ancestor = frame; ancestor; ancestor = ancestor.parentFrame()) chain.push(ancestor);
|
|
493
|
+
chain.reverse();
|
|
494
|
+
if (chain.length === 1) return this._describeMainFrame(page);
|
|
495
|
+
const selectorPromises = [];
|
|
496
|
+
for (let i = 0; i < chain.length - 1; i++) selectorPromises.push(findFrameSelector(chain[i + 1]));
|
|
497
|
+
const result = await (0, _timeoutRunner.raceAgainstDeadline)(() => Promise.all(selectorPromises), (0, _utils2.monotonicTime)() + 2000);
|
|
498
|
+
if (!result.timedOut && result.result.every(selector => !!selector)) {
|
|
499
|
+
return {
|
|
500
|
+
pageAlias,
|
|
501
|
+
isMainFrame: false,
|
|
502
|
+
selectorsChain: result.result
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
// Best effort to find a selector for the frame.
|
|
506
|
+
const selectorsChain = [];
|
|
507
|
+
for (let i = 0; i < chain.length - 1; i++) {
|
|
508
|
+
if (chain[i].name()) selectorsChain.push(`iframe[name=${(0, _stringUtils.quoteCSSAttributeValue)(chain[i].name())}]`);else selectorsChain.push(`iframe[src=${(0, _stringUtils.quoteCSSAttributeValue)(chain[i].url())}]`);
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
pageAlias,
|
|
512
|
+
isMainFrame: false,
|
|
513
|
+
selectorsChain
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
testIdAttributeName() {
|
|
517
|
+
return this._params.testIdAttributeName || this._context.selectors().testIdAttributeName() || 'data-testid';
|
|
518
|
+
}
|
|
519
|
+
async _performAction(frame, action) {
|
|
520
|
+
// Commit last action so that no further signals are added to it.
|
|
521
|
+
this._generator.commitLastAction();
|
|
522
|
+
const frameDescription = await this._describeFrame(frame);
|
|
523
|
+
const actionInContext = {
|
|
524
|
+
frame: frameDescription,
|
|
525
|
+
action
|
|
526
|
+
};
|
|
527
|
+
const perform = async (action, params, cb) => {
|
|
528
|
+
const callMetadata = {
|
|
529
|
+
id: `call@${(0, _utils2.createGuid)()}`,
|
|
530
|
+
apiName: 'frame.' + action,
|
|
531
|
+
objectId: frame.guid,
|
|
532
|
+
pageId: frame._page.guid,
|
|
533
|
+
frameId: frame.guid,
|
|
534
|
+
startTime: (0, _utils2.monotonicTime)(),
|
|
535
|
+
endTime: 0,
|
|
536
|
+
wallTime: Date.now(),
|
|
537
|
+
type: 'Frame',
|
|
538
|
+
method: action,
|
|
539
|
+
params,
|
|
540
|
+
log: []
|
|
541
|
+
};
|
|
542
|
+
this._generator.willPerformAction(actionInContext);
|
|
543
|
+
try {
|
|
544
|
+
await frame.instrumentation.onBeforeCall(frame, callMetadata);
|
|
545
|
+
await cb(callMetadata);
|
|
546
|
+
} catch (e) {
|
|
547
|
+
callMetadata.endTime = (0, _utils2.monotonicTime)();
|
|
548
|
+
await frame.instrumentation.onAfterCall(frame, callMetadata);
|
|
549
|
+
this._generator.performedActionFailed(actionInContext);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
callMetadata.endTime = (0, _utils2.monotonicTime)();
|
|
553
|
+
await frame.instrumentation.onAfterCall(frame, callMetadata);
|
|
554
|
+
const timer = setTimeout(() => {
|
|
555
|
+
// Commit the action after 5 seconds so that no further signals are added to it.
|
|
556
|
+
actionInContext.committed = true;
|
|
557
|
+
this._timers.delete(timer);
|
|
558
|
+
}, 5000);
|
|
559
|
+
this._generator.didPerformAction(actionInContext);
|
|
560
|
+
this._timers.add(timer);
|
|
561
|
+
};
|
|
562
|
+
const kActionTimeout = 5000;
|
|
563
|
+
if (action.name === 'click') {
|
|
564
|
+
const {
|
|
565
|
+
options
|
|
566
|
+
} = (0, _utils.toClickOptions)(action);
|
|
567
|
+
await perform('click', {
|
|
568
|
+
selector: action.selector
|
|
569
|
+
}, callMetadata => frame.click(callMetadata, action.selector, {
|
|
570
|
+
...options,
|
|
571
|
+
timeout: kActionTimeout,
|
|
572
|
+
strict: true
|
|
573
|
+
}));
|
|
574
|
+
}
|
|
575
|
+
if (action.name === 'press') {
|
|
576
|
+
const modifiers = (0, _utils.toModifiers)(action.modifiers);
|
|
577
|
+
const shortcut = [...modifiers, action.key].join('+');
|
|
578
|
+
await perform('press', {
|
|
579
|
+
selector: action.selector,
|
|
580
|
+
key: shortcut
|
|
581
|
+
}, callMetadata => frame.press(callMetadata, action.selector, shortcut, {
|
|
582
|
+
timeout: kActionTimeout,
|
|
583
|
+
strict: true
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
if (action.name === 'check') await perform('check', {
|
|
587
|
+
selector: action.selector
|
|
588
|
+
}, callMetadata => frame.check(callMetadata, action.selector, {
|
|
589
|
+
timeout: kActionTimeout,
|
|
590
|
+
strict: true
|
|
591
|
+
}));
|
|
592
|
+
if (action.name === 'uncheck') await perform('uncheck', {
|
|
593
|
+
selector: action.selector
|
|
594
|
+
}, callMetadata => frame.uncheck(callMetadata, action.selector, {
|
|
595
|
+
timeout: kActionTimeout,
|
|
596
|
+
strict: true
|
|
597
|
+
}));
|
|
598
|
+
if (action.name === 'select') {
|
|
599
|
+
const values = action.options.map(value => ({
|
|
600
|
+
value
|
|
601
|
+
}));
|
|
602
|
+
await perform('selectOption', {
|
|
603
|
+
selector: action.selector,
|
|
604
|
+
values
|
|
605
|
+
}, callMetadata => frame.selectOption(callMetadata, action.selector, [], values, {
|
|
606
|
+
timeout: kActionTimeout,
|
|
607
|
+
strict: true
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
async _recordAction(frame, action) {
|
|
612
|
+
// Commit last action so that no further signals are added to it.
|
|
613
|
+
this._generator.commitLastAction();
|
|
614
|
+
const frameDescription = await this._describeFrame(frame);
|
|
615
|
+
const actionInContext = {
|
|
616
|
+
frame: frameDescription,
|
|
617
|
+
action
|
|
618
|
+
};
|
|
619
|
+
this._generator.addAction(actionInContext);
|
|
620
|
+
}
|
|
621
|
+
_onFrameNavigated(frame, page) {
|
|
622
|
+
const pageAlias = this._pageAliases.get(page);
|
|
623
|
+
this._generator.signal(pageAlias, frame, {
|
|
624
|
+
name: 'navigation',
|
|
625
|
+
url: frame.url()
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
_onPopup(page, popup) {
|
|
629
|
+
const pageAlias = this._pageAliases.get(page);
|
|
630
|
+
const popupAlias = this._pageAliases.get(popup);
|
|
631
|
+
this._generator.signal(pageAlias, page.mainFrame(), {
|
|
632
|
+
name: 'popup',
|
|
633
|
+
popupAlias
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
_onDownload(page) {
|
|
637
|
+
const pageAlias = this._pageAliases.get(page);
|
|
638
|
+
++this._lastDownloadOrdinal;
|
|
639
|
+
this._generator.signal(pageAlias, page.mainFrame(), {
|
|
640
|
+
name: 'download',
|
|
641
|
+
downloadAlias: this._lastDownloadOrdinal ? String(this._lastDownloadOrdinal) : ''
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
_onDialog(page) {
|
|
645
|
+
const pageAlias = this._pageAliases.get(page);
|
|
646
|
+
++this._lastDialogOrdinal;
|
|
647
|
+
this._generator.signal(pageAlias, page.mainFrame(), {
|
|
648
|
+
name: 'dialog',
|
|
649
|
+
dialogAlias: this._lastDialogOrdinal ? String(this._lastDialogOrdinal) : ''
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
ContextRecorder.Events = {
|
|
654
|
+
Change: 'change'
|
|
655
|
+
};
|
|
656
|
+
function languageForFile(file) {
|
|
657
|
+
if (file.endsWith('.py')) return 'python';
|
|
658
|
+
if (file.endsWith('.java')) return 'java';
|
|
659
|
+
if (file.endsWith('.cs')) return 'csharp';
|
|
660
|
+
return 'javascript';
|
|
661
|
+
}
|
|
662
|
+
class ThrottledFile {
|
|
663
|
+
constructor(file) {
|
|
664
|
+
this._file = void 0;
|
|
665
|
+
this._timer = void 0;
|
|
666
|
+
this._text = void 0;
|
|
667
|
+
this._file = file;
|
|
668
|
+
}
|
|
669
|
+
setContent(text) {
|
|
670
|
+
this._text = text;
|
|
671
|
+
if (!this._timer) this._timer = setTimeout(() => this.flush(), 250);
|
|
672
|
+
}
|
|
673
|
+
flush() {
|
|
674
|
+
if (this._timer) {
|
|
675
|
+
clearTimeout(this._timer);
|
|
676
|
+
this._timer = undefined;
|
|
677
|
+
}
|
|
678
|
+
if (this._text) fs.writeFileSync(this._file, this._text);
|
|
679
|
+
this._text = undefined;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function isScreenshotCommand(metadata) {
|
|
683
|
+
return metadata.method.toLowerCase().includes('screenshot');
|
|
684
|
+
}
|
|
685
|
+
async function findFrameSelector(frame) {
|
|
686
|
+
try {
|
|
687
|
+
const parent = frame.parentFrame();
|
|
688
|
+
const frameElement = await frame.frameElement();
|
|
689
|
+
if (!frameElement || !parent) return;
|
|
690
|
+
const utility = await parent._utilityContext();
|
|
691
|
+
const injected = await utility.injectedScript();
|
|
692
|
+
const selector = await injected.evaluate((injected, element) => {
|
|
693
|
+
return injected.generateSelectorSimple(element, {
|
|
694
|
+
testIdAttributeName: '',
|
|
695
|
+
omitInternalEngines: true
|
|
696
|
+
});
|
|
697
|
+
}, frameElement);
|
|
698
|
+
return selector;
|
|
699
|
+
} catch (e) {}
|
|
700
|
+
}
|