patchright-core 1.48.2
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/README.md +3 -0
- package/ThirdPartyNotices.txt +1548 -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 +24 -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 +24 -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 +23 -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 +23 -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 +24 -0
- package/browsers.json +57 -0
- package/cli.js +18 -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 +95 -0
- package/lib/cli/program.js +589 -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 +285 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +145 -0
- package/lib/client/browserContext.js +583 -0
- package/lib/client/browserType.js +241 -0
- package/lib/client/cdpSession.js +53 -0
- package/lib/client/channelOwner.js +235 -0
- package/lib/client/clientHelper.js +57 -0
- package/lib/client/clientInstrumentation.js +50 -0
- package/lib/client/clock.js +69 -0
- package/lib/client/connection.js +333 -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 +135 -0
- package/lib/client/elementHandle.js +321 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/eventEmitter.js +314 -0
- package/lib/client/events.js +94 -0
- package/lib/client/fetch.js +391 -0
- package/lib/client/fileChooser.js +45 -0
- package/lib/client/frame.js +504 -0
- package/lib/client/harRouter.js +99 -0
- package/lib/client/input.js +111 -0
- package/lib/client/jsHandle.js +121 -0
- package/lib/client/jsonPipe.js +35 -0
- package/lib/client/localUtils.js +36 -0
- package/lib/client/locator.js +441 -0
- package/lib/client/network.js +762 -0
- package/lib/client/page.js +770 -0
- package/lib/client/playwright.js +80 -0
- package/lib/client/selectors.js +67 -0
- package/lib/client/stream.js +54 -0
- package/lib/client/tracing.js +134 -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/clockSource.js +7 -0
- package/lib/generated/consoleApiSource.js +7 -0
- package/lib/generated/injectedScriptSource.js +7 -0
- package/lib/generated/pollingRecorderSource.js +7 -0
- package/lib/generated/utilityScriptSource.js +7 -0
- package/lib/generated/webSocketMockSource.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 +173 -0
- package/lib/protocol/transport.js +82 -0
- package/lib/protocol/validator.js +2760 -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/bidi/bidiBrowser.js +311 -0
- package/lib/server/bidi/bidiChromium.js +124 -0
- package/lib/server/bidi/bidiConnection.js +206 -0
- package/lib/server/bidi/bidiExecutionContext.js +159 -0
- package/lib/server/bidi/bidiFirefox.js +104 -0
- package/lib/server/bidi/bidiInput.js +158 -0
- package/lib/server/bidi/bidiNetworkManager.js +338 -0
- package/lib/server/bidi/bidiOverCdp.js +103 -0
- package/lib/server/bidi/bidiPage.js +529 -0
- package/lib/server/bidi/bidiPdf.js +140 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +93 -0
- package/lib/server/bidi/third_party/bidiKeyboard.js +238 -0
- package/lib/server/bidi/third_party/bidiProtocol.js +139 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +144 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +221 -0
- package/lib/server/browser.js +148 -0
- package/lib/server/browserContext.js +666 -0
- package/lib/server/browserType.js +335 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +350 -0
- package/lib/server/chromium/chromiumSwitches.js +36 -0
- package/lib/server/chromium/crAccessibility.js +237 -0
- package/lib/server/chromium/crBrowser.js +522 -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 +143 -0
- package/lib/server/chromium/crExecutionContext.js +149 -0
- package/lib/server/chromium/crInput.js +171 -0
- package/lib/server/chromium/crNetworkManager.js +809 -0
- package/lib/server/chromium/crPage.js +1235 -0
- package/lib/server/chromium/crPdf.js +153 -0
- package/lib/server/chromium/crProtocolHelper.js +133 -0
- package/lib/server/chromium/crServiceWorker.js +111 -0
- package/lib/server/chromium/defaultFontFamilies.js +145 -0
- package/lib/server/chromium/videoRecorder.js +155 -0
- package/lib/server/clock.js +133 -0
- package/lib/server/codegen/csharp.js +299 -0
- package/lib/server/codegen/java.js +235 -0
- package/lib/server/codegen/javascript.js +223 -0
- package/lib/server/codegen/jsonl.js +47 -0
- package/lib/server/codegen/language.js +88 -0
- package/lib/server/codegen/languages.js +30 -0
- package/lib/server/codegen/python.js +265 -0
- package/lib/server/codegen/types.js +5 -0
- package/lib/server/console.js +57 -0
- package/lib/server/cookieStore.js +185 -0
- package/lib/server/debugController.js +234 -0
- package/lib/server/debugger.js +132 -0
- package/lib/server/deviceDescriptors.js +26 -0
- package/lib/server/deviceDescriptorsSource.json +1669 -0
- package/lib/server/dialog.js +71 -0
- package/lib/server/dispatchers/androidDispatcher.js +193 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +368 -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 +395 -0
- package/lib/server/dispatchers/electronDispatcher.js +93 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +228 -0
- package/lib/server/dispatchers/frameDispatcher.js +286 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +97 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +59 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +413 -0
- package/lib/server/dispatchers/networkDispatchers.js +221 -0
- package/lib/server/dispatchers/pageDispatcher.js +367 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +107 -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/webSocketRouteDispatcher.js +189 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +58 -0
- package/lib/server/dom.js +845 -0
- package/lib/server/download.js +60 -0
- package/lib/server/electron/electron.js +296 -0
- package/lib/server/electron/loader.js +57 -0
- package/lib/server/errors.js +68 -0
- package/lib/server/fetch.js +656 -0
- package/lib/server/fileChooser.js +42 -0
- package/lib/server/fileUploadUtils.js +75 -0
- package/lib/server/firefox/ffAccessibility.js +216 -0
- package/lib/server/firefox/ffBrowser.js +460 -0
- package/lib/server/firefox/ffConnection.js +168 -0
- package/lib/server/firefox/ffExecutionContext.js +135 -0
- package/lib/server/firefox/ffInput.js +150 -0
- package/lib/server/firefox/ffNetworkManager.js +233 -0
- package/lib/server/firefox/ffPage.js +559 -0
- package/lib/server/firefox/firefox.js +99 -0
- package/lib/server/formData.js +75 -0
- package/lib/server/frameSelectors.js +171 -0
- package/lib/server/frames.js +1808 -0
- package/lib/server/har/harRecorder.js +139 -0
- package/lib/server/har/harTracer.js +542 -0
- package/lib/server/helper.js +103 -0
- package/lib/server/index.js +114 -0
- package/lib/server/input.js +310 -0
- package/lib/server/instrumentation.js +70 -0
- package/lib/server/isomorphic/utilityScriptSerializers.js +226 -0
- package/lib/server/javascript.js +299 -0
- package/lib/server/launchApp.js +91 -0
- package/lib/server/macEditingCommands.js +139 -0
- package/lib/server/network.js +617 -0
- package/lib/server/page.js +819 -0
- package/lib/server/pipeTransport.js +85 -0
- package/lib/server/playwright.js +88 -0
- package/lib/server/progress.js +102 -0
- package/lib/server/protocolError.js +49 -0
- package/lib/server/recorder/contextRecorder.js +299 -0
- package/lib/server/recorder/recorderApp.js +196 -0
- package/lib/server/recorder/recorderCollection.js +116 -0
- package/lib/server/recorder/recorderFrontend.js +5 -0
- package/lib/server/recorder/recorderInTraceViewer.js +144 -0
- package/lib/server/recorder/recorderRunner.js +155 -0
- package/lib/server/recorder/recorderUtils.js +112 -0
- package/lib/server/recorder/throttledFile.js +46 -0
- package/lib/server/recorder.js +329 -0
- package/lib/server/registry/browserFetcher.js +168 -0
- package/lib/server/registry/dependencies.js +322 -0
- package/lib/server/registry/index.js +1005 -0
- package/lib/server/registry/nativeDeps.js +490 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +138 -0
- package/lib/server/screenshotter.js +348 -0
- package/lib/server/selectors.js +73 -0
- package/lib/server/socksClientCertificatesInterceptor.js +340 -0
- package/lib/server/socksInterceptor.js +100 -0
- package/lib/server/trace/recorder/snapshotter.js +172 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +493 -0
- package/lib/server/trace/recorder/tracing.js +542 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +93 -0
- package/lib/server/trace/viewer/traceViewer.js +213 -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 +329 -0
- package/lib/server/webkit/wkConnection.js +173 -0
- package/lib/server/webkit/wkExecutionContext.js +143 -0
- package/lib/server/webkit/wkInput.js +169 -0
- package/lib/server/webkit/wkInterceptableRequest.js +162 -0
- package/lib/server/webkit/wkPage.js +1219 -0
- package/lib/server/webkit/wkProvisionalPage.js +94 -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 +174 -0
- package/lib/utils/debug.js +46 -0
- package/lib/utils/debugLogger.js +91 -0
- package/lib/utils/env.js +49 -0
- package/lib/utils/eventsHelper.js +38 -0
- package/lib/utils/expectUtils.js +33 -0
- package/lib/utils/fileUtils.js +205 -0
- package/lib/utils/happy-eyeballs.js +194 -0
- package/lib/utils/headers.js +52 -0
- package/lib/utils/hostPlatform.js +133 -0
- package/lib/utils/httpServer.js +237 -0
- package/lib/utils/index.js +368 -0
- package/lib/utils/isomorphic/cssParser.js +250 -0
- package/lib/utils/isomorphic/cssTokenizer.js +979 -0
- package/lib/utils/isomorphic/locatorGenerators.js +642 -0
- package/lib/utils/isomorphic/locatorParser.js +179 -0
- package/lib/utils/isomorphic/locatorUtils.js +62 -0
- package/lib/utils/isomorphic/mimeType.js +29 -0
- package/lib/utils/isomorphic/recorderUtils.js +195 -0
- package/lib/utils/isomorphic/selectorParser.js +397 -0
- package/lib/utils/isomorphic/stringUtils.js +139 -0
- package/lib/utils/isomorphic/traceUtils.js +39 -0
- package/lib/utils/isomorphic/urlMatch.js +120 -0
- package/lib/utils/linuxUtils.js +78 -0
- package/lib/utils/manualPromise.js +109 -0
- package/lib/utils/multimap.js +75 -0
- package/lib/utils/network.js +160 -0
- package/lib/utils/processLauncher.js +248 -0
- package/lib/utils/profiler.js +53 -0
- package/lib/utils/rtti.js +44 -0
- package/lib/utils/semaphore.js +51 -0
- package/lib/utils/spawnAsync.js +45 -0
- package/lib/utils/stackTrace.js +121 -0
- package/lib/utils/task.js +58 -0
- package/lib/utils/time.js +37 -0
- package/lib/utils/timeoutRunner.js +66 -0
- package/lib/utils/traceUtils.js +44 -0
- package/lib/utils/userAgent.js +105 -0
- package/lib/utils/wsServer.js +127 -0
- package/lib/utils/zipFile.js +75 -0
- package/lib/utils/zones.js +62 -0
- package/lib/utilsBundle.js +82 -0
- package/lib/utilsBundleImpl/index.js +53 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +66 -0
- package/lib/vite/recorder/assets/codeMirrorModule-baozm8ur.js +24 -0
- package/lib/vite/recorder/assets/codeMirrorModule-ez37Vkbh.css +1 -0
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-2ElAIWFB.js +42 -0
- package/lib/vite/recorder/assets/index-BW-aOBcL.css +1 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-Bh1rfd2w.js +24 -0
- package/lib/vite/traceViewer/assets/inspectorTab-7GHnKvSD.js +64 -0
- package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +1 -0
- package/lib/vite/traceViewer/assets/workbench-DPQnTHYP.js +9 -0
- package/lib/vite/traceViewer/assets/xtermModule-BeNbaIVa.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.ez37Vkbh.css +1 -0
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/embedded.BlHoW5LY.js +2 -0
- package/lib/vite/traceViewer/embedded.html +18 -0
- package/lib/vite/traceViewer/embedded.w7WN2u1R.css +1 -0
- package/lib/vite/traceViewer/index.CrbWWHbf.css +1 -0
- package/lib/vite/traceViewer/index.DaWVfou1.js +2 -0
- package/lib/vite/traceViewer/index.html +29 -0
- package/lib/vite/traceViewer/inspectorTab.DLjBDrQR.css +1 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
- package/lib/vite/traceViewer/recorder.C4zxcvd2.js +2 -0
- package/lib/vite/traceViewer/recorder.html +17 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +3 -0
- package/lib/vite/traceViewer/uiMode.CAYqod-m.css +1 -0
- package/lib/vite/traceViewer/uiMode.html +20 -0
- package/lib/vite/traceViewer/uiMode.mTXWniJb.js +5 -0
- package/lib/vite/traceViewer/workbench.D3JVcA9K.css +1 -0
- package/lib/vite/traceViewer/xtermModule.DSXBckUd.css +32 -0
- package/lib/zipBundle.js +25 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +44 -0
- package/types/protocol.d.ts +21571 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +22519 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "InvalidSelectorError", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _cssParser.InvalidSelectorError;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.customCSSNames = void 0;
|
|
13
|
+
Object.defineProperty(exports, "isInvalidSelectorError", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _cssParser.isInvalidSelectorError;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.parseAttributeSelector = parseAttributeSelector;
|
|
20
|
+
exports.parseSelector = parseSelector;
|
|
21
|
+
exports.splitSelectorByFrame = splitSelectorByFrame;
|
|
22
|
+
exports.stringifySelector = stringifySelector;
|
|
23
|
+
exports.visitAllSelectorParts = visitAllSelectorParts;
|
|
24
|
+
var _cssParser = require("./cssParser");
|
|
25
|
+
/**
|
|
26
|
+
* Copyright (c) Microsoft Corporation.
|
|
27
|
+
*
|
|
28
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29
|
+
* you may not use this file except in compliance with the License.
|
|
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
|
+
const kNestedSelectorNames = new Set(['internal:has', 'internal:has-not', 'internal:and', 'internal:or', 'internal:chain', 'left-of', 'right-of', 'above', 'below', 'near']);
|
|
42
|
+
const kNestedSelectorNamesWithDistance = new Set(['left-of', 'right-of', 'above', 'below', 'near']);
|
|
43
|
+
const customCSSNames = exports.customCSSNames = new Set(['not', 'is', 'where', 'has', 'scope', 'light', 'visible', 'text', 'text-matches', 'text-is', 'has-text', 'above', 'below', 'right-of', 'left-of', 'near', 'nth-match']);
|
|
44
|
+
function parseSelector(selector) {
|
|
45
|
+
const parsedStrings = parseSelectorString(selector);
|
|
46
|
+
const parts = [];
|
|
47
|
+
for (const part of parsedStrings.parts) {
|
|
48
|
+
if (part.name === 'css' || part.name === 'css:light') {
|
|
49
|
+
if (part.name === 'css:light') part.body = ':light(' + part.body + ')';
|
|
50
|
+
const parsedCSS = (0, _cssParser.parseCSS)(part.body, customCSSNames);
|
|
51
|
+
parts.push({
|
|
52
|
+
name: 'css',
|
|
53
|
+
body: parsedCSS.selector,
|
|
54
|
+
source: part.body
|
|
55
|
+
});
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (kNestedSelectorNames.has(part.name)) {
|
|
59
|
+
let innerSelector;
|
|
60
|
+
let distance;
|
|
61
|
+
try {
|
|
62
|
+
const unescaped = JSON.parse('[' + part.body + ']');
|
|
63
|
+
if (!Array.isArray(unescaped) || unescaped.length < 1 || unescaped.length > 2 || typeof unescaped[0] !== 'string') throw new _cssParser.InvalidSelectorError(`Malformed selector: ${part.name}=` + part.body);
|
|
64
|
+
innerSelector = unescaped[0];
|
|
65
|
+
if (unescaped.length === 2) {
|
|
66
|
+
if (typeof unescaped[1] !== 'number' || !kNestedSelectorNamesWithDistance.has(part.name)) throw new _cssParser.InvalidSelectorError(`Malformed selector: ${part.name}=` + part.body);
|
|
67
|
+
distance = unescaped[1];
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
throw new _cssParser.InvalidSelectorError(`Malformed selector: ${part.name}=` + part.body);
|
|
71
|
+
}
|
|
72
|
+
const nested = {
|
|
73
|
+
name: part.name,
|
|
74
|
+
source: part.body,
|
|
75
|
+
body: {
|
|
76
|
+
parsed: parseSelector(innerSelector),
|
|
77
|
+
distance
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const lastFrame = [...nested.body.parsed.parts].reverse().find(part => part.name === 'internal:control' && part.body === 'enter-frame');
|
|
81
|
+
const lastFrameIndex = lastFrame ? nested.body.parsed.parts.indexOf(lastFrame) : -1;
|
|
82
|
+
// Allow nested selectors to start with the same frame selector.
|
|
83
|
+
if (lastFrameIndex !== -1 && selectorPartsEqual(nested.body.parsed.parts.slice(0, lastFrameIndex + 1), parts.slice(0, lastFrameIndex + 1))) nested.body.parsed.parts.splice(0, lastFrameIndex + 1);
|
|
84
|
+
parts.push(nested);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
parts.push({
|
|
88
|
+
...part,
|
|
89
|
+
source: part.body
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (kNestedSelectorNames.has(parts[0].name)) throw new _cssParser.InvalidSelectorError(`"${parts[0].name}" selector cannot be first`);
|
|
93
|
+
return {
|
|
94
|
+
capture: parsedStrings.capture,
|
|
95
|
+
parts
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function splitSelectorByFrame(selectorText) {
|
|
99
|
+
const selector = parseSelector(selectorText);
|
|
100
|
+
const result = [];
|
|
101
|
+
let chunk = {
|
|
102
|
+
parts: []
|
|
103
|
+
};
|
|
104
|
+
let chunkStartIndex = 0;
|
|
105
|
+
for (let i = 0; i < selector.parts.length; ++i) {
|
|
106
|
+
const part = selector.parts[i];
|
|
107
|
+
if (part.name === 'internal:control' && part.body === 'enter-frame') {
|
|
108
|
+
if (!chunk.parts.length) throw new _cssParser.InvalidSelectorError('Selector cannot start with entering frame, select the iframe first');
|
|
109
|
+
result.push(chunk);
|
|
110
|
+
chunk = {
|
|
111
|
+
parts: []
|
|
112
|
+
};
|
|
113
|
+
chunkStartIndex = i + 1;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (selector.capture === i) chunk.capture = i - chunkStartIndex;
|
|
117
|
+
chunk.parts.push(part);
|
|
118
|
+
}
|
|
119
|
+
if (!chunk.parts.length) throw new _cssParser.InvalidSelectorError(`Selector cannot end with entering frame, while parsing selector ${selectorText}`);
|
|
120
|
+
result.push(chunk);
|
|
121
|
+
if (typeof selector.capture === 'number' && typeof result[result.length - 1].capture !== 'number') throw new _cssParser.InvalidSelectorError(`Can not capture the selector before diving into the frame. Only use * after the last frame has been selected`);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function selectorPartsEqual(list1, list2) {
|
|
125
|
+
return stringifySelector({
|
|
126
|
+
parts: list1
|
|
127
|
+
}) === stringifySelector({
|
|
128
|
+
parts: list2
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function stringifySelector(selector, forceEngineName) {
|
|
132
|
+
if (typeof selector === 'string') return selector;
|
|
133
|
+
return selector.parts.map((p, i) => {
|
|
134
|
+
let includeEngine = true;
|
|
135
|
+
if (!forceEngineName && i !== selector.capture) {
|
|
136
|
+
if (p.name === 'css') includeEngine = false;else if (p.name === 'xpath' && p.source.startsWith('//') || p.source.startsWith('..')) includeEngine = false;
|
|
137
|
+
}
|
|
138
|
+
const prefix = includeEngine ? p.name + '=' : '';
|
|
139
|
+
return `${i === selector.capture ? '*' : ''}${prefix}${p.source}`;
|
|
140
|
+
}).join(' >> ');
|
|
141
|
+
}
|
|
142
|
+
function visitAllSelectorParts(selector, visitor) {
|
|
143
|
+
const visit = (selector, nested) => {
|
|
144
|
+
for (const part of selector.parts) {
|
|
145
|
+
visitor(part, nested);
|
|
146
|
+
if (kNestedSelectorNames.has(part.name)) visit(part.body.parsed, true);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
visit(selector, false);
|
|
150
|
+
}
|
|
151
|
+
function parseSelectorString(selector) {
|
|
152
|
+
let index = 0;
|
|
153
|
+
let quote;
|
|
154
|
+
let start = 0;
|
|
155
|
+
const result = {
|
|
156
|
+
parts: []
|
|
157
|
+
};
|
|
158
|
+
const append = () => {
|
|
159
|
+
const part = selector.substring(start, index).trim();
|
|
160
|
+
const eqIndex = part.indexOf('=');
|
|
161
|
+
let name;
|
|
162
|
+
let body;
|
|
163
|
+
if (eqIndex !== -1 && part.substring(0, eqIndex).trim().match(/^[a-zA-Z_0-9-+:*]+$/)) {
|
|
164
|
+
name = part.substring(0, eqIndex).trim();
|
|
165
|
+
body = part.substring(eqIndex + 1);
|
|
166
|
+
} else if (part.length > 1 && part[0] === '"' && part[part.length - 1] === '"') {
|
|
167
|
+
name = 'text';
|
|
168
|
+
body = part;
|
|
169
|
+
} else if (part.length > 1 && part[0] === "'" && part[part.length - 1] === "'") {
|
|
170
|
+
name = 'text';
|
|
171
|
+
body = part;
|
|
172
|
+
} else if (/^\(*\/\//.test(part) || part.startsWith('..')) {
|
|
173
|
+
// If selector starts with '//' or '//' prefixed with multiple opening
|
|
174
|
+
// parenthesis, consider xpath. @see https://github.com/microsoft/playwright/issues/817
|
|
175
|
+
// If selector starts with '..', consider xpath as well.
|
|
176
|
+
name = 'xpath';
|
|
177
|
+
body = part;
|
|
178
|
+
} else {
|
|
179
|
+
name = 'css';
|
|
180
|
+
body = part;
|
|
181
|
+
}
|
|
182
|
+
let capture = false;
|
|
183
|
+
if (name[0] === '*') {
|
|
184
|
+
capture = true;
|
|
185
|
+
name = name.substring(1);
|
|
186
|
+
}
|
|
187
|
+
result.parts.push({
|
|
188
|
+
name,
|
|
189
|
+
body
|
|
190
|
+
});
|
|
191
|
+
if (capture) {
|
|
192
|
+
if (result.capture !== undefined) throw new _cssParser.InvalidSelectorError(`Only one of the selectors can capture using * modifier`);
|
|
193
|
+
result.capture = result.parts.length - 1;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
if (!selector.includes('>>')) {
|
|
197
|
+
index = selector.length;
|
|
198
|
+
append();
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
const shouldIgnoreTextSelectorQuote = () => {
|
|
202
|
+
const prefix = selector.substring(start, index);
|
|
203
|
+
const match = prefix.match(/^\s*text\s*=(.*)$/);
|
|
204
|
+
// Must be a text selector with some text before the quote.
|
|
205
|
+
return !!match && !!match[1];
|
|
206
|
+
};
|
|
207
|
+
while (index < selector.length) {
|
|
208
|
+
const c = selector[index];
|
|
209
|
+
if (c === '\\' && index + 1 < selector.length) {
|
|
210
|
+
index += 2;
|
|
211
|
+
} else if (c === quote) {
|
|
212
|
+
quote = undefined;
|
|
213
|
+
index++;
|
|
214
|
+
} else if (!quote && (c === '"' || c === '\'' || c === '`') && !shouldIgnoreTextSelectorQuote()) {
|
|
215
|
+
quote = c;
|
|
216
|
+
index++;
|
|
217
|
+
} else if (!quote && c === '>' && selector[index + 1] === '>') {
|
|
218
|
+
append();
|
|
219
|
+
index += 2;
|
|
220
|
+
start = index;
|
|
221
|
+
} else {
|
|
222
|
+
index++;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
append();
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
function parseAttributeSelector(selector, allowUnquotedStrings) {
|
|
229
|
+
let wp = 0;
|
|
230
|
+
let EOL = selector.length === 0;
|
|
231
|
+
const next = () => selector[wp] || '';
|
|
232
|
+
const eat1 = () => {
|
|
233
|
+
const result = next();
|
|
234
|
+
++wp;
|
|
235
|
+
EOL = wp >= selector.length;
|
|
236
|
+
return result;
|
|
237
|
+
};
|
|
238
|
+
const syntaxError = stage => {
|
|
239
|
+
if (EOL) throw new _cssParser.InvalidSelectorError(`Unexpected end of selector while parsing selector \`${selector}\``);
|
|
240
|
+
throw new _cssParser.InvalidSelectorError(`Error while parsing selector \`${selector}\` - unexpected symbol "${next()}" at position ${wp}` + (stage ? ' during ' + stage : ''));
|
|
241
|
+
};
|
|
242
|
+
function skipSpaces() {
|
|
243
|
+
while (!EOL && /\s/.test(next())) eat1();
|
|
244
|
+
}
|
|
245
|
+
function isCSSNameChar(char) {
|
|
246
|
+
// https://www.w3.org/TR/css-syntax-3/#ident-token-diagram
|
|
247
|
+
return char >= '\u0080' // non-ascii
|
|
248
|
+
|| char >= '\u0030' && char <= '\u0039' // digit
|
|
249
|
+
|| char >= '\u0041' && char <= '\u005a' // uppercase letter
|
|
250
|
+
|| char >= '\u0061' && char <= '\u007a' // lowercase letter
|
|
251
|
+
|| char >= '\u0030' && char <= '\u0039' // digit
|
|
252
|
+
|| char === '\u005f' // "_"
|
|
253
|
+
|| char === '\u002d'; // "-"
|
|
254
|
+
}
|
|
255
|
+
function readIdentifier() {
|
|
256
|
+
let result = '';
|
|
257
|
+
skipSpaces();
|
|
258
|
+
while (!EOL && isCSSNameChar(next())) result += eat1();
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
function readQuotedString(quote) {
|
|
262
|
+
let result = eat1();
|
|
263
|
+
if (result !== quote) syntaxError('parsing quoted string');
|
|
264
|
+
while (!EOL && next() !== quote) {
|
|
265
|
+
if (next() === '\\') eat1();
|
|
266
|
+
result += eat1();
|
|
267
|
+
}
|
|
268
|
+
if (next() !== quote) syntaxError('parsing quoted string');
|
|
269
|
+
result += eat1();
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
function readRegularExpression() {
|
|
273
|
+
if (eat1() !== '/') syntaxError('parsing regular expression');
|
|
274
|
+
let source = '';
|
|
275
|
+
let inClass = false;
|
|
276
|
+
// https://262.ecma-international.org/11.0/#sec-literals-regular-expression-literals
|
|
277
|
+
while (!EOL) {
|
|
278
|
+
if (next() === '\\') {
|
|
279
|
+
source += eat1();
|
|
280
|
+
if (EOL) syntaxError('parsing regular expression');
|
|
281
|
+
} else if (inClass && next() === ']') {
|
|
282
|
+
inClass = false;
|
|
283
|
+
} else if (!inClass && next() === '[') {
|
|
284
|
+
inClass = true;
|
|
285
|
+
} else if (!inClass && next() === '/') {
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
source += eat1();
|
|
289
|
+
}
|
|
290
|
+
if (eat1() !== '/') syntaxError('parsing regular expression');
|
|
291
|
+
let flags = '';
|
|
292
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
293
|
+
while (!EOL && next().match(/[dgimsuy]/)) flags += eat1();
|
|
294
|
+
try {
|
|
295
|
+
return new RegExp(source, flags);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
throw new _cssParser.InvalidSelectorError(`Error while parsing selector \`${selector}\`: ${e.message}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function readAttributeToken() {
|
|
301
|
+
let token = '';
|
|
302
|
+
skipSpaces();
|
|
303
|
+
if (next() === `'` || next() === `"`) token = readQuotedString(next()).slice(1, -1);else token = readIdentifier();
|
|
304
|
+
if (!token) syntaxError('parsing property path');
|
|
305
|
+
return token;
|
|
306
|
+
}
|
|
307
|
+
function readOperator() {
|
|
308
|
+
skipSpaces();
|
|
309
|
+
let op = '';
|
|
310
|
+
if (!EOL) op += eat1();
|
|
311
|
+
if (!EOL && op !== '=') op += eat1();
|
|
312
|
+
if (!['=', '*=', '^=', '$=', '|=', '~='].includes(op)) syntaxError('parsing operator');
|
|
313
|
+
return op;
|
|
314
|
+
}
|
|
315
|
+
function readAttribute() {
|
|
316
|
+
// skip leading [
|
|
317
|
+
eat1();
|
|
318
|
+
|
|
319
|
+
// read attribute name:
|
|
320
|
+
// foo.bar
|
|
321
|
+
// 'foo' . "ba zz"
|
|
322
|
+
const jsonPath = [];
|
|
323
|
+
jsonPath.push(readAttributeToken());
|
|
324
|
+
skipSpaces();
|
|
325
|
+
while (next() === '.') {
|
|
326
|
+
eat1();
|
|
327
|
+
jsonPath.push(readAttributeToken());
|
|
328
|
+
skipSpaces();
|
|
329
|
+
}
|
|
330
|
+
// check property is truthy: [enabled]
|
|
331
|
+
if (next() === ']') {
|
|
332
|
+
eat1();
|
|
333
|
+
return {
|
|
334
|
+
name: jsonPath.join('.'),
|
|
335
|
+
jsonPath,
|
|
336
|
+
op: '<truthy>',
|
|
337
|
+
value: null,
|
|
338
|
+
caseSensitive: false
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
const operator = readOperator();
|
|
342
|
+
let value = undefined;
|
|
343
|
+
let caseSensitive = true;
|
|
344
|
+
skipSpaces();
|
|
345
|
+
if (next() === '/') {
|
|
346
|
+
if (operator !== '=') throw new _cssParser.InvalidSelectorError(`Error while parsing selector \`${selector}\` - cannot use ${operator} in attribute with regular expression`);
|
|
347
|
+
value = readRegularExpression();
|
|
348
|
+
} else if (next() === `'` || next() === `"`) {
|
|
349
|
+
value = readQuotedString(next()).slice(1, -1);
|
|
350
|
+
skipSpaces();
|
|
351
|
+
if (next() === 'i' || next() === 'I') {
|
|
352
|
+
caseSensitive = false;
|
|
353
|
+
eat1();
|
|
354
|
+
} else if (next() === 's' || next() === 'S') {
|
|
355
|
+
caseSensitive = true;
|
|
356
|
+
eat1();
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
value = '';
|
|
360
|
+
while (!EOL && (isCSSNameChar(next()) || next() === '+' || next() === '.')) value += eat1();
|
|
361
|
+
if (value === 'true') {
|
|
362
|
+
value = true;
|
|
363
|
+
} else if (value === 'false') {
|
|
364
|
+
value = false;
|
|
365
|
+
} else {
|
|
366
|
+
if (!allowUnquotedStrings) {
|
|
367
|
+
value = +value;
|
|
368
|
+
if (Number.isNaN(value)) syntaxError('parsing attribute value');
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
skipSpaces();
|
|
373
|
+
if (next() !== ']') syntaxError('parsing attribute value');
|
|
374
|
+
eat1();
|
|
375
|
+
if (operator !== '=' && typeof value !== 'string') throw new _cssParser.InvalidSelectorError(`Error while parsing selector \`${selector}\` - cannot use ${operator} in attribute with non-string matching value - ${value}`);
|
|
376
|
+
return {
|
|
377
|
+
name: jsonPath.join('.'),
|
|
378
|
+
jsonPath,
|
|
379
|
+
op: operator,
|
|
380
|
+
value,
|
|
381
|
+
caseSensitive
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const result = {
|
|
385
|
+
name: '',
|
|
386
|
+
attributes: []
|
|
387
|
+
};
|
|
388
|
+
result.name = readIdentifier();
|
|
389
|
+
skipSpaces();
|
|
390
|
+
while (next() === '[') {
|
|
391
|
+
result.attributes.push(readAttribute());
|
|
392
|
+
skipSpaces();
|
|
393
|
+
}
|
|
394
|
+
if (!EOL) syntaxError(undefined);
|
|
395
|
+
if (!result.name && !result.attributes.length) throw new _cssParser.InvalidSelectorError(`Error while parsing selector \`${selector}\` - selector cannot be empty`);
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cacheNormalizedWhitespaces = cacheNormalizedWhitespaces;
|
|
7
|
+
exports.cssEscape = cssEscape;
|
|
8
|
+
exports.escapeForAttributeSelector = escapeForAttributeSelector;
|
|
9
|
+
exports.escapeForTextSelector = escapeForTextSelector;
|
|
10
|
+
exports.escapeHTML = escapeHTML;
|
|
11
|
+
exports.escapeHTMLAttribute = escapeHTMLAttribute;
|
|
12
|
+
exports.escapeRegExp = escapeRegExp;
|
|
13
|
+
exports.escapeWithQuotes = escapeWithQuotes;
|
|
14
|
+
exports.isString = isString;
|
|
15
|
+
exports.normalizeEscapedRegexQuotes = normalizeEscapedRegexQuotes;
|
|
16
|
+
exports.normalizeWhiteSpace = normalizeWhiteSpace;
|
|
17
|
+
exports.quoteCSSAttributeValue = quoteCSSAttributeValue;
|
|
18
|
+
exports.toSnakeCase = toSnakeCase;
|
|
19
|
+
exports.toTitleCase = toTitleCase;
|
|
20
|
+
exports.trimString = trimString;
|
|
21
|
+
exports.trimStringWithEllipsis = trimStringWithEllipsis;
|
|
22
|
+
/**
|
|
23
|
+
* Copyright (c) Microsoft Corporation.
|
|
24
|
+
*
|
|
25
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26
|
+
* you may not use this file except in compliance with the License.
|
|
27
|
+
* You may obtain a copy of the License at
|
|
28
|
+
*
|
|
29
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
+
*
|
|
31
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
+
* See the License for the specific language governing permissions and
|
|
35
|
+
* limitations under the License.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
// NOTE: this function should not be used to escape any selectors.
|
|
39
|
+
function escapeWithQuotes(text, char = '\'') {
|
|
40
|
+
const stringified = JSON.stringify(text);
|
|
41
|
+
const escapedText = stringified.substring(1, stringified.length - 1).replace(/\\"/g, '"');
|
|
42
|
+
if (char === '\'') return char + escapedText.replace(/[']/g, '\\\'') + char;
|
|
43
|
+
if (char === '"') return char + escapedText.replace(/["]/g, '\\"') + char;
|
|
44
|
+
if (char === '`') return char + escapedText.replace(/[`]/g, '`') + char;
|
|
45
|
+
throw new Error('Invalid escape char');
|
|
46
|
+
}
|
|
47
|
+
function isString(obj) {
|
|
48
|
+
return typeof obj === 'string' || obj instanceof String;
|
|
49
|
+
}
|
|
50
|
+
function toTitleCase(name) {
|
|
51
|
+
return name.charAt(0).toUpperCase() + name.substring(1);
|
|
52
|
+
}
|
|
53
|
+
function toSnakeCase(name) {
|
|
54
|
+
// E.g. ignoreHTTPSErrors => ignore_https_errors.
|
|
55
|
+
return name.replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/([A-Z])([A-Z][a-z])/g, '$1_$2').toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
function cssEscape(s) {
|
|
58
|
+
let result = '';
|
|
59
|
+
for (let i = 0; i < s.length; i++) result += cssEscapeOne(s, i);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
function quoteCSSAttributeValue(text) {
|
|
63
|
+
return `"${cssEscape(text).replace(/\\ /g, ' ')}"`;
|
|
64
|
+
}
|
|
65
|
+
function cssEscapeOne(s, i) {
|
|
66
|
+
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
67
|
+
const c = s.charCodeAt(i);
|
|
68
|
+
if (c === 0x0000) return '\uFFFD';
|
|
69
|
+
if (c >= 0x0001 && c <= 0x001f || c >= 0x0030 && c <= 0x0039 && (i === 0 || i === 1 && s.charCodeAt(0) === 0x002d)) return '\\' + c.toString(16) + ' ';
|
|
70
|
+
if (i === 0 && c === 0x002d && s.length === 1) return '\\' + s.charAt(i);
|
|
71
|
+
if (c >= 0x0080 || c === 0x002d || c === 0x005f || c >= 0x0030 && c <= 0x0039 || c >= 0x0041 && c <= 0x005a || c >= 0x0061 && c <= 0x007a) return s.charAt(i);
|
|
72
|
+
return '\\' + s.charAt(i);
|
|
73
|
+
}
|
|
74
|
+
let normalizedWhitespaceCache;
|
|
75
|
+
function cacheNormalizedWhitespaces() {
|
|
76
|
+
normalizedWhitespaceCache = new Map();
|
|
77
|
+
}
|
|
78
|
+
function normalizeWhiteSpace(text) {
|
|
79
|
+
var _normalizedWhitespace;
|
|
80
|
+
let result = (_normalizedWhitespace = normalizedWhitespaceCache) === null || _normalizedWhitespace === void 0 ? void 0 : _normalizedWhitespace.get(text);
|
|
81
|
+
if (result === undefined) {
|
|
82
|
+
var _normalizedWhitespace2;
|
|
83
|
+
result = text.replace(/\u200b/g, '').trim().replace(/\s+/g, ' ');
|
|
84
|
+
(_normalizedWhitespace2 = normalizedWhitespaceCache) === null || _normalizedWhitespace2 === void 0 || _normalizedWhitespace2.set(text, result);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
function normalizeEscapedRegexQuotes(source) {
|
|
89
|
+
// This function reverses the effect of escapeRegexForSelector below.
|
|
90
|
+
// Odd number of backslashes followed by the quote -> remove unneeded backslash.
|
|
91
|
+
return source.replace(/(^|[^\\])(\\\\)*\\(['"`])/g, '$1$2$3');
|
|
92
|
+
}
|
|
93
|
+
function escapeRegexForSelector(re) {
|
|
94
|
+
// Unicode mode does not allow "identity character escapes", so we do not escape and
|
|
95
|
+
// hope that it does not contain quotes and/or >> signs.
|
|
96
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape
|
|
97
|
+
// TODO: rework RE usages in internal selectors away from literal representation to json, e.g. {source,flags}.
|
|
98
|
+
if (re.unicode || re.unicodeSets) return String(re);
|
|
99
|
+
// Even number of backslashes followed by the quote -> insert a backslash.
|
|
100
|
+
return String(re).replace(/(^|[^\\])(\\\\)*(["'`])/g, '$1$2\\$3').replace(/>>/g, '\\>\\>');
|
|
101
|
+
}
|
|
102
|
+
function escapeForTextSelector(text, exact) {
|
|
103
|
+
if (typeof text !== 'string') return escapeRegexForSelector(text);
|
|
104
|
+
return `${JSON.stringify(text)}${exact ? 's' : 'i'}`;
|
|
105
|
+
}
|
|
106
|
+
function escapeForAttributeSelector(value, exact) {
|
|
107
|
+
if (typeof value !== 'string') return escapeRegexForSelector(value);
|
|
108
|
+
// TODO: this should actually be
|
|
109
|
+
// cssEscape(value).replace(/\\ /g, ' ')
|
|
110
|
+
// However, our attribute selectors do not conform to CSS parsing spec,
|
|
111
|
+
// so we escape them differently.
|
|
112
|
+
return `"${value.replace(/\\/g, '\\\\').replace(/["]/g, '\\"')}"${exact ? 's' : 'i'}`;
|
|
113
|
+
}
|
|
114
|
+
function trimString(input, cap, suffix = '') {
|
|
115
|
+
if (input.length <= cap) return input;
|
|
116
|
+
const chars = [...input];
|
|
117
|
+
if (chars.length > cap) return chars.slice(0, cap - suffix.length).join('') + suffix;
|
|
118
|
+
return chars.join('');
|
|
119
|
+
}
|
|
120
|
+
function trimStringWithEllipsis(input, cap) {
|
|
121
|
+
return trimString(input, cap, '\u2026');
|
|
122
|
+
}
|
|
123
|
+
function escapeRegExp(s) {
|
|
124
|
+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
125
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
126
|
+
}
|
|
127
|
+
const escaped = {
|
|
128
|
+
'&': '&',
|
|
129
|
+
'<': '<',
|
|
130
|
+
'>': '>',
|
|
131
|
+
'"': '"',
|
|
132
|
+
'\'': '''
|
|
133
|
+
};
|
|
134
|
+
function escapeHTMLAttribute(s) {
|
|
135
|
+
return s.replace(/[&<>"']/ug, char => escaped[char]);
|
|
136
|
+
}
|
|
137
|
+
function escapeHTML(s) {
|
|
138
|
+
return s.replace(/[&<]/ug, char => escaped[char]);
|
|
139
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseClientSideCallMetadata = parseClientSideCallMetadata;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Microsoft Corporation.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function parseClientSideCallMetadata(data) {
|
|
24
|
+
const result = new Map();
|
|
25
|
+
const {
|
|
26
|
+
files,
|
|
27
|
+
stacks
|
|
28
|
+
} = data;
|
|
29
|
+
for (const s of stacks) {
|
|
30
|
+
const [id, ff] = s;
|
|
31
|
+
result.set(`call@${id}`, ff.map(f => ({
|
|
32
|
+
file: files[f[0]],
|
|
33
|
+
line: f[1],
|
|
34
|
+
column: f[2],
|
|
35
|
+
function: f[3]
|
|
36
|
+
})));
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.constructURLBasedOnBaseURL = constructURLBasedOnBaseURL;
|
|
7
|
+
exports.globToRegex = globToRegex;
|
|
8
|
+
exports.urlMatches = urlMatches;
|
|
9
|
+
exports.urlMatchesEqual = urlMatchesEqual;
|
|
10
|
+
var _stringUtils = require("./stringUtils");
|
|
11
|
+
/**
|
|
12
|
+
* Copyright (c) Microsoft Corporation.
|
|
13
|
+
*
|
|
14
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License.
|
|
16
|
+
* You may obtain a copy of the License at
|
|
17
|
+
*
|
|
18
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
+
* See the License for the specific language governing permissions and
|
|
24
|
+
* limitations under the License.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
|
28
|
+
const escapedChars = new Set(['$', '^', '+', '.', '*', '(', ')', '|', '\\', '?', '{', '}', '[', ']']);
|
|
29
|
+
function globToRegex(glob) {
|
|
30
|
+
const tokens = ['^'];
|
|
31
|
+
let inGroup = false;
|
|
32
|
+
for (let i = 0; i < glob.length; ++i) {
|
|
33
|
+
const c = glob[i];
|
|
34
|
+
if (c === '\\' && i + 1 < glob.length) {
|
|
35
|
+
const char = glob[++i];
|
|
36
|
+
tokens.push(escapedChars.has(char) ? '\\' + char : char);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (c === '*') {
|
|
40
|
+
const beforeDeep = glob[i - 1];
|
|
41
|
+
let starCount = 1;
|
|
42
|
+
while (glob[i + 1] === '*') {
|
|
43
|
+
starCount++;
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
const afterDeep = glob[i + 1];
|
|
47
|
+
const isDeep = starCount > 1 && (beforeDeep === '/' || beforeDeep === undefined) && (afterDeep === '/' || afterDeep === undefined);
|
|
48
|
+
if (isDeep) {
|
|
49
|
+
tokens.push('((?:[^/]*(?:\/|$))*)');
|
|
50
|
+
i++;
|
|
51
|
+
} else {
|
|
52
|
+
tokens.push('([^/]*)');
|
|
53
|
+
}
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
switch (c) {
|
|
57
|
+
case '?':
|
|
58
|
+
tokens.push('.');
|
|
59
|
+
break;
|
|
60
|
+
case '[':
|
|
61
|
+
tokens.push('[');
|
|
62
|
+
break;
|
|
63
|
+
case ']':
|
|
64
|
+
tokens.push(']');
|
|
65
|
+
break;
|
|
66
|
+
case '{':
|
|
67
|
+
inGroup = true;
|
|
68
|
+
tokens.push('(');
|
|
69
|
+
break;
|
|
70
|
+
case '}':
|
|
71
|
+
inGroup = false;
|
|
72
|
+
tokens.push(')');
|
|
73
|
+
break;
|
|
74
|
+
case ',':
|
|
75
|
+
if (inGroup) {
|
|
76
|
+
tokens.push('|');
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
tokens.push('\\' + c);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
tokens.push(escapedChars.has(c) ? '\\' + c : c);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
tokens.push('$');
|
|
86
|
+
return new RegExp(tokens.join(''));
|
|
87
|
+
}
|
|
88
|
+
function isRegExp(obj) {
|
|
89
|
+
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
90
|
+
}
|
|
91
|
+
function urlMatchesEqual(match1, match2) {
|
|
92
|
+
if (isRegExp(match1) && isRegExp(match2)) return match1.source === match2.source && match1.flags === match2.flags;
|
|
93
|
+
return match1 === match2;
|
|
94
|
+
}
|
|
95
|
+
function urlMatches(baseURL, urlString, match) {
|
|
96
|
+
if (match === undefined || match === '') return true;
|
|
97
|
+
if ((0, _stringUtils.isString)(match) && !match.startsWith('*')) match = constructURLBasedOnBaseURL(baseURL, match);
|
|
98
|
+
if ((0, _stringUtils.isString)(match)) match = globToRegex(match);
|
|
99
|
+
if (isRegExp(match)) return match.test(urlString);
|
|
100
|
+
if (typeof match === 'string' && match === urlString) return true;
|
|
101
|
+
const url = parsedURL(urlString);
|
|
102
|
+
if (!url) return false;
|
|
103
|
+
if (typeof match === 'string') return url.pathname === match;
|
|
104
|
+
if (typeof match !== 'function') throw new Error('url parameter should be string, RegExp or function');
|
|
105
|
+
return match(url);
|
|
106
|
+
}
|
|
107
|
+
function parsedURL(url) {
|
|
108
|
+
try {
|
|
109
|
+
return new URL(url);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function constructURLBasedOnBaseURL(baseURL, givenURL) {
|
|
115
|
+
try {
|
|
116
|
+
return new URL(givenURL, baseURL).toString();
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return givenURL;
|
|
119
|
+
}
|
|
120
|
+
}
|