Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from microsoft:main #31

Open
wants to merge 2,421 commits into
base: main
Choose a base branch
from
Open

[pull] main from microsoft:main #31

wants to merge 2,421 commits into from

Conversation

pull[bot]
Copy link

@pull pull bot commented Aug 25, 2024

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

alanleedev and others added 30 commits August 20, 2024 12:18
Summary:
Pull Request resolved: facebook#46072

Introducing extension fuctions in PixelUtils to replace Java static methods so Kotlin code can be more readable.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D61372704

fbshipit-source-id: 489a74d60cd1463f0b1fad6f7c33925cec4000d2
…wing you to see both sides (facebook#46117)

Summary:
Pull Request resolved: facebook#46117

Currently in large cursive blocks like layout effect we can't tell what the slow leaf function is. With this fixed I'm able to root cause more complex issues in layout effects.

Reviewed By: NickGerleman

Differential Revision: D61486415

fbshipit-source-id: 5a4043b35eedcabcbea86953aac2173f66d7257b
Summary:
Pull Request resolved: facebook#46118

Changelog: [Internal]

Reviewed By: cyan33

Differential Revision: D61550740

fbshipit-source-id: 8c201b8f79416dec13ece9c671405af7b2de9c8c
Summary:
Pull Request resolved: facebook#46076

This will add the shadows to iOS as well. let's see if anyone notices 🙂. I also removed dead styles, and removed some of the extra (excessive) padding specific to Android where the previous shadows would overlap.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D61421903

fbshipit-source-id: 887fa5aa96e3b0b4f81114ee814897c218db2b76
Summary:
Pull Request resolved: facebook#46080

1. Force the examples to be alphabetized, where the hand-maintained list has some examples that are not
2. Remove reundant/not useful UI

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D61430910

fbshipit-source-id: 1f3e116fe81502faa7a72f2720912e26c9f04bb2
…in TextLayoutManager (facebook#46104)

Summary:
Pull Request resolved: facebook#46104

We want to use `PrecomputedText` to store glyph-level measurements on underlying Android Spannable. This means we need to consistently reuse the same Spannable, instead of recreating them on measurement.

We have an opaque cache ID used by Android, for spannables originating from uncontrolled TextInput on UI-thread side. We also have `AttributedStringBox`, for a kind of similar purpose on iOS, which allows passing opaque pointer to the `TextLayoutManager`. This is only used for the `measure` function.

This change makes us consistently use `AttributedStringBox` at the TextLayoutManager boundary, to let us migrate calls across TextLayoutManager to all pass opaque handle to underlying Spannable we will store, instead of passing the AttributedString each time. For now, every place previously passing an AttributedString value still passes one.

There were also some egregious cases of accepting very large structures by value, causing unneeded copies. I changed the APIs to accept anything potentially larger than two pointers to pass by reference instead.

This change is technically breaking, to any 3p code calling into TextLayoutManager (IIRC live-markdown exposed prefabs for this, but should be able to adapt fairly easily).

Changelog:
[General][Breaking] - Always use AttributedStringBox instead of AttributedString in TextLayoutManager

Reviewed By: joevilches

Differential Revision: D61484999

fbshipit-source-id: 07c5600cd917f2dab3d24559a25f27e0872ebddc
Summary:
Pull Request resolved: facebook#46116

If your app raises an early js exception, and you cold start it, often you'll see this error:

```
SurfaceRegistryBinding::startSurface failed. Global was not installed.
```

{F1807125099}

The reason why is because two different threads race to redbox:
* The nativemodule thread: the early js error (reported [here](https://fburl.com/code/vcrqzsdp))
* The javascript thread: the SurfaceRegistryBinding error (a subsequent native -> js call)

After this diff, the early js error will **not jump onto the nativemodule thread** to report this error.

This ensures that we "always" (to the best of my knowledge) see the early js error first.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D61339213

fbshipit-source-id: f1b9ab30150b87377817c2fd93ca349c406db48b
…compared to native viewconfig (facebook#45859)

Summary:
Pull Request resolved: facebook#45859

"Fabric without SVCs" configuration is nearly gone, and so it doesn't make sense to need to add no-op methods, on normally Paper only code, etc to satisfy native viewconfig. These particular warnings are then more often noise, than things we need to action on.

Checking for native code to be present can also break development where users are using distributed native app, slightly older than JS.

This keeps the warning, only if static viewconfigs are missing native view config attributes (i.e. new prop would only be exposed to Paper, instead of only exposed to Fabric)

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D60575253

fbshipit-source-id: 1c118274b92eb7922c0dd92df060b24e44fceb3d
Summary:
Pull Request resolved: facebook#46119

Straightforward migration of the `Appearance` module to use ESM named exports.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D61567882

fbshipit-source-id: a4a5a9771de001bd41cb0e23ba066f150267a55d
Summary:
Pull Request resolved: facebook#46121

Updates `Appearance` on Android to supply the native module to `NativeEventEmitter` so that the native listener count can be managed like it is on iOS.

This was previously required by macOS and iOS. Android and Windows also already implement:

```
interface NativeModule {
  addListener(eventType: string): void;
  removeListeners(count: number): void;
}
```

So we should start passing `NativeAppearance` into the `NativeEventEmitter` constructor across all platforms.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D61567883

fbshipit-source-id: 1b3b76de9be3f35cacba1acbc43f6dcc0b41fde5
Summary:
Pull Request resolved: facebook#46120

Currently, the implementation of `Appearance` duplicates the validation logic of string `colorScheme` values multiple times.

This leads to more complicated code and also unnecessary work in certain edge cases (e.g. when `NativeAppearance` is not registered).

This refactors `Appearance` to be simpler and to do less work. I've also configured `NativeAppearance.setColorScheme` to be non-nullable because it has existed since 2023.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D61567881

fbshipit-source-id: 61cb51709dc716ad97ae1397105414e74fe57a28
Summary:
Pull Request resolved: facebook#46122

Implements a JavaScript cache for `colorScheme` in the `Appearance` module, so that we avoid potentially expensive and unnecessary native property accesses.

Changelog:
[General][Changed] - Improved `Appearance.getColorScheme` performance

Reviewed By: rickhanlonii

Differential Revision: D61567880

fbshipit-source-id: ca316946d68114b05239daa17105c85e637efe07
…6113)

Summary:
Pull Request resolved: facebook#46113

changelog: [internal]

This showed promised in local tracing but that failed to translate to real perf improvement. Unshipping.

Reviewed By: christophpurrer

Differential Revision: D61537744

fbshipit-source-id: 03a2a69a6fed32a6b493bc17372e3783b9db2d1e
…cebook#46132)

Summary:
Pull Request resolved: facebook#46132

Temporaily disable the `nativeSourceCodeFetching` capability — which reverts this to the legacy handling in the Inspector Proxy.

This is because we've noticed performance issues when loading large bundle source maps, particularly on Android, with a nontrivial path to optimising this ([raising the frontend `IO.read` size](facebookexperimental/rn-chrome-devtools-frontend#97) further is leading to WebSocket disconnections on Android 😐).

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D61543480

fbshipit-source-id: ee66b4cebd40f8cc6466270c5875df744d2b588a
Summary:
Pull Request resolved: facebook#46131

React native 0.75.0, 0.75.1 and 0.75.2 has been published to NPM without the latest tag, despite the tag being on the commit.

When debugging why that's happened, I realized that we were not downloading the tags when checking out the repo.

This change fixes that.

{F1816667285}

## Changelog:
[Internal] - Publish React native as latest when the latest tag is specified on git

Reviewed By: cortinico

Differential Revision: D61593398

fbshipit-source-id: 96bf8346207f0bd0b01f60ee09879210d12d30af
Summary:
In the recent 0.75 release I've noticed new `CONFIG_CMD` option in `react-native-xcode.sh`. But this option was not used. Insted when set `CONFIG_APP` was used.

This seems like a bug. As the usage before this PR would be as follow:

```bash
export CONFIG_CMD=true
export CONFIG_APP="/path/to/node /path/to/node_modules/react-native/cli.js config"
```

After this PR

```
export CONFIG_CMD="/path/to/node /path/to/node_modules/react-native/cli.js config"
```

This PR also removed unused explicite `--config-cmd "$CONFIG"` flag, as this is always overwriten by the code above, by default to `--config-cmd" "$NODE_BINARY $NODE_ARGS $REACT_NATIVE_DIR/cli.js config`.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[iOS][Fixed] - Use CONFIG_CMD if set

Pull Request resolved: facebook#46112

Test Plan: I've set `CONFIG_CMD` and run Xcode Release build to check that the set command is executed.

Reviewed By: christophpurrer

Differential Revision: D61545010

Pulled By: blakef

fbshipit-source-id: ebbf8ebc08404bc6816277518a3b86c6f7e41e6e
Summary:
Pull Request resolved: facebook#46136

Changelog:
[iOS] - Update RNTester and HelloWorld template app to `min iOS 15.1`

Reviewed By: philIip, blakef

Differential Revision: D61604036

fbshipit-source-id: 9260b9b51a9c976792fd9d705b9b6a35a88a7f86
Summary:
Pull Request resolved: facebook#46137

Changelog:
[iOS] - Bump OSS Build infra to min iOS 15.1

Reference: react-native-community/discussions-and-proposals#812

Reviewed By: christophpurrer

Differential Revision: D61577939

fbshipit-source-id: 8f2929af266f61aedd55358b13d08544fd79e434
Summary:
Pull Request resolved: facebook#46135

Changelog:
[iOS] - Bump iOS min version for CI

Reviewed By: cipolleschi

Differential Revision: D61604034

fbshipit-source-id: 5d2b0001b6437e62c64d821e36a4183096e8ef74
…6125)

Summary:
Clean up some dead code after some refactoring of RCTParagraphComponentView.  cc cipolleschi

## Changelog:

[IOS] [FIXED] - Clean up RCTParagraphComponentView & RCTParagraphTextView

Pull Request resolved: facebook#46125

Test Plan: CI green.

Reviewed By: christophpurrer

Differential Revision: D61603193

Pulled By: cipolleschi

fbshipit-source-id: a357e8c5355707b2296462de513010acda4ee6ea
…irtualized list (facebook#46103)

Summary:
Pull Request resolved: facebook#46103

Reducing the boundary of rerender of virtual lists. Previously with prop: "strictMode={true}" the VirtualizedList still re rendered each CellRenderer component. Because method getDerivedStateFromProps generated every time a new uniq state and the cells didn’t have a PureComponent. It helps to improve react performance for lists which have 5+ elements.

I reused recomended approach from react doc https://legacy.reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html#what-about-memoization

changelog: [internal]
Optimizing CellRenderer of VirtualizedList

Reviewed By: NickGerleman, sammy-SC

Differential Revision: D61493434

fbshipit-source-id: 917a33e48bd2f18e8ac150e5701d2e7c45dbe879
Summary:
Pull Request resolved: facebook#46140

Add default value for newArchitectureEnabled param

changelog: [internal] internal

Reviewed By: shwanton

Differential Revision: D61621224

fbshipit-source-id: 728c91f9ce10ad5872f86cd223ea30c8f9bde413
Summary:
Pull Request resolved: facebook#46139

Potential fix for IndexOutOfBounds crashes in clipping rect logic.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D61615009

fbshipit-source-id: 1208e11286ad2a84c22262462832a66396a1b35b
Summary:
Pull Request resolved: facebook#46148

Try fixing the import path (not sure if access from external modules is allowed though).

Changelog: [Internal]

Reviewed By: realsoelynn

Differential Revision: D61643115

fbshipit-source-id: a840ee375430b0e20050a36b695a5a4c93c29258
Summary:
Pull Request resolved: facebook#46146

Changelog: [Internal]

`unit` is of type `UnitType`, so there's no reason to have a default case here.

i found this because my build failed when pulling in this dependency, there was a compiler flag that enforced that all cases must be enumerated. this seems like the right practice anyways.

Reviewed By: NickGerleman

Differential Revision: D61635463

fbshipit-source-id: b84b5518f2a17e792309f85ae91514a17abad295
…46172)

Summary:
In facebook#45102 I've implemented a baseline alignment function for the new architecture. I've noticed one thing I've missed previously - `locationForGlyphAtIndex` is [relative to the line fragment](https://developer.apple.com/documentation/appkit/nslayoutmanager/1403239-locationforglyphatindex), not the container. This means that the attachments would be put in the wrong place in multiline text.

This PR fixes that by adding the position of the entire line to the attachment position.

## Changelog:

[IOS] [FIXED] - Fixed baseline attachment position in multiline text

Pull Request resolved: facebook#46172

Test Plan:
Checked on relevant example of RNTester.

|Before|After|
|-|-|
|<img width="546" alt="Screenshot 2024-08-22 at 15 53 14" src="https://github.com/user-attachments/assets/c1861655-9253-44fd-9f2f-796aff83df1e">|<img width="546" alt="Screenshot 2024-08-22 at 15 52 37" src="https://github.com/user-attachments/assets/27f07bc7-a8f6-4696-a414-815e7ece642c">|

Reviewed By: andrewdacenko

Differential Revision: D61662006

Pulled By: cipolleschi

fbshipit-source-id: 5eafdae1800c06d9fc61bfac99584e6e25a05c24
… layer (facebook#46138)

Summary:
Pull Request resolved: facebook#46138

jorge-cab noticed that filters on iOS do not fit the shape of the layer if we have rounded corners. Fix is pretty straight forward.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D61612655

fbshipit-source-id: 91785ed10a039e031c5440bde131c1583ba3992a
…46157)

Summary:
Pull Request resolved: facebook#46157

Changelog: [internal]

This improves the handling of disconnected nodes in `MutationObserver`. Specifically:
* When observing a node, if the node is disconnected (unmounted) this is just a no-op (without logging errors). We can't observe an unmounted node.
* When disconnecting the observer, if the observed nodes are disconnected, we get the target shadow node from an internal map, which we always have access to if we successfully started observing the node. If this logs an error now, it's something to look into but it won't generally log it if the target is just disconnected. That will work correctly.

Reviewed By: bvanderhoof

Differential Revision: D61655856

fbshipit-source-id: d18a885350ef000fc563c85f6775ba864d184ad1
…ook#46156)

Summary:
Pull Request resolved: facebook#46156

Changelog: [internal]

This improves the handling of disconnected nodes in `IntersectionObserver`. Specifically:
* When observing a node, if the node is disconnected (unmounted) this is just a no-op (without logging errors). We can't observe an unmounted node.
* When disconnecting the observer, if the observed nodes are disconnected, we get the target shadow node from an internal map, which we always have access to if we successfully started observing the node. If this logs an error now, it's something to look into but it won't generally log it if the target is just disconnected. That will work correctly.

Reviewed By: bvanderhoof

Differential Revision: D61656597

fbshipit-source-id: 6a39c878acc976ddc0789260106da104a3f2a57f
Summary:
Pull Request resolved: facebook#45966

JSI performs the check itself, no need to do it here. Plus, bytecode
bundles must not be zero terminated.

## Changelog:

[IOS] [FIXED] - Fixes NSDataBigString length calculation

Reviewed By: realsoelynn

Differential Revision: D61058869

fbshipit-source-id: 15b99ef13f9aebd11ff410d02c21db8e46cc6ac3
dependabot bot and others added 6 commits November 19, 2024 16:50
Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.6.
- [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md)
- [Commits](moxystudio/node-cross-spawn@v7.0.3...v7.0.6)

---
updated-dependencies:
- dependency-name: cross-spawn
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Summary:
Fix AppKit exception throws when focusing text inputs by calling becomeFirstResponder directly on the backing text input view.

Making a view first responder has to happen through the window using makeFirstResponder.

Test Plan:
- Run Zeratul with Fabric
- Focus the search text input above the message threads
- Click inside the active message thread to trigger the auto-focus of the composer
- The composer gets focus without AppKit throwing an exception.

 https://pxl.cl/3dVMx

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D48696690
…stance

Summary:
Fix AppKit exception throws when blurring text inputs by calling `resignFirstResponder` directly on the backing text input view.
Resigning the first responder state has to happen through the window by calling `[window makeFirstResponder:nil]` which will:
- call `resignFirstResponder` on the current first responder
- if successful, the window will become the first responder

Test Plan:
- Run Zeratul with Fabric
- Focus the search text input above the message threads
- Click inside the active message thread to trigger the auto-focus of the composer and the blur on the search field
- The focused field resigns the first responder status without throwing an exception

 https://pxl.cl/3GvZD

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D50700782
Summary:
On macOS, Core Animation layers have their anchor point set to (0,0) which is the top-left. On iOS the anchor point is set to (0.5, 0.5) which matches the center.

Transforms assigned to views are built based on having the anchor point at the center.

This diff updates the transform matrix to apply to transform from the center.

Test Plan:
Check zoom/rotation animations in Zeratul.

| Before | After |
|--|
|  https://pxl.cl/3G8HG  |  https://pxl.cl/3G8HQ  |

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D50628807

Tasks: T161413049
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function T(e){return e=(e=e.replace(/^\w[+\w.-]*:\/\//i,"")).replace(/^\/\//,"")}function w(e){const s=new URL("https://"+T(e).replace(":*","").replace("*","wildcard_placeholder")).hostname.replace("wildcard_placeholder","*"),t=/^\[[\d:]+\]/;return T(e).match(t)&&!s.match(t)?"["+s+"]":s}function N(e){return e.startsWith("//")?e.replace("//","https://"):e}function v(e,s){const t=new URL(N(e.replace(":*","").replace("*","wildcard_placeholder"))),o=s.map((e=>new URL(N(e)))),i=t.hostname.toLowerCase(),n=i.startsWith("wildcard_placeholder."),a=i.replace(/^\wildcard_placeholder/i,""),c=t.pathname,r="/"!==c;for(const e of o){const s=e.hostname;if(s.endsWith(a)&&(n||i===s)){if(r)if(c.endsWith("/")){if(!e.pathname.startsWith(c))continue}else if(e.pathname!==c)continue;return e}}return null}function A(e,s){const t=Object.keys(e.directives);for(const o of t){const t=e.directives[o];t&&s(o,t)}}

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High library

This replaces only the first occurrence of "*".
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function T(e){return e=(e=e.replace(/^\w[+\w.-]*:\/\//i,"")).replace(/^\/\//,"")}function w(e){const s=new URL("https://"+T(e).replace(":*","").replace("*","wildcard_placeholder")).hostname.replace("wildcard_placeholder","*"),t=/^\[[\d:]+\]/;return T(e).match(t)&&!s.match(t)?"["+s+"]":s}function N(e){return e.startsWith("//")?e.replace("//","https://"):e}function v(e,s){const t=new URL(N(e.replace(":*","").replace("*","wildcard_placeholder"))),o=s.map((e=>new URL(N(e)))),i=t.hostname.toLowerCase(),n=i.startsWith("wildcard_placeholder."),a=i.replace(/^\wildcard_placeholder/i,""),c=t.pathname,r="/"!==c;for(const e of o){const s=e.hostname;if(s.endsWith(a)&&(n||i===s)){if(r)if(c.endsWith("/")){if(!e.pathname.startsWith(c))continue}else if(e.pathname!==c)continue;return e}}return null}function A(e,s){const t=Object.keys(e.directives);for(const o of t){const t=e.directives[o];t&&s(o,t)}}

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High library

This replaces only the first occurrence of "*".
@@ -1 +1 @@
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e=e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t=t||(t={})),function(e){e.Navigation="navigation"}(n=n||(n={}));var r=Object.freeze({__proto__:null,get SelectorType(){return e},get StepType(){return t},get AssertedEventType(){return n}});function a(e){throw new Error(`Unknown step type: ${e.type}`)}const i=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function l(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function c(e){return"object"==typeof e&&null!==e}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function w(e){if(l(e,"target")&&u(e.target))return e.target}function d(e){if(l(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(l(e,t)){const n=e[t];if(p(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(l(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function y(e,t){if(l(e,t))return h(e,t)}function g(e,t){if(l(e,t))return b(e,t)}function v(e,t){if(l(e,t))return m(e,t)}function b(e,t){if(l(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!l(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!u(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!u(e))throw new Error("Selector element is not a string");return e})):e}))}function S(e){if(l(e,"selectors"))return E(e)}function L(e){if(!c(e))throw new Error("Asserted event is not an object");if(!l(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:g(e,"url"),title:g(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(l(t,"timeout")&&p(t.timeout)&&!P(t.timeout))throw new Error(j);return{type:e,assertedEvents:l(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:l(t,"timeout")&&p(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:w(t)}}function C(e,t){return{...A(e,t),frame:d(t)}}function $(e,t){return{...C(e,t),selectors:E(t)}}function x(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:y(e,"duration")},n=g(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const a=g(e,"button");if(a){if(!function(e){return"string"==typeof e&&s.has(e)}(a))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=a}return t}function T(e,n){if(!c(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!l(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!u(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...$(t.Click,e),...x(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...$(t.DoubleClick,e),...x(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...$(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...$(t.Change,e),type:t.Change,value:b(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:b(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:b(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...C(t.Scroll,e),type:t.Scroll,x:y(e,"x"),y:y(e,"y"),selectors:S(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:w(e),url:b(e,"url")}}(e);case t.CustomStep:return function(e){if(!l(e,"name"))throw new Error("customStep is missing name");if(!u(e.name))throw new Error("customStep's name is not a string");return{...C(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:l(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=g(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(l(e,"attributes")&&(!c(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(l(e,"properties")&&!c(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...$(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:y(e,"count"),visible:v(e,"visible"),attributes:l(e,"attributes")?e.attributes:void 0,properties:l(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!l(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...C(t.WaitForExpression,e),type:t.WaitForExpression,expression:b(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function I(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push(T(r,n));return t}const N=1,V=3e4,j="Timeout is not between 1 and 30000 milliseconds";function P(e){return e>=1&&e<=3e4}function W(e){if(!c(e))throw new Error("Recording is not an object");if(!l(e,"title"))throw new Error("Recording is missing `title`");if(!u(e.title))throw new Error("Recording `title` is not a string");if(l(e,"timeout")&&!p(e.timeout))throw new Error("Recording `timeout` is not a number");if(!l(e,"steps"))throw new Error("Recording is missing `steps`");if(l(e,"timeout")&&p(e.timeout)&&!P(e.timeout))throw new Error(j);return t={title:e.title,timeout:l(e,"timeout")&&p(e.timeout)?e.timeout:void 0,selectorAttribute:l(e,"selectorAttribute")&&u(e.selectorAttribute)?e.selectorAttribute:void 0,steps:I(e.steps)},JSON.parse(JSON.stringify(t));var t}function O(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}class R{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class M extends R{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const a=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+a)}}function B(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function D(e,t,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(e,n):a?a.value=n:t.set(e,n),n}var H,K,U;class q{constructor(e){H.set(this,void 0),K.set(this,0),U.set(this,[]),D(this,H,e,"f")}appendLine(e){const t=e.split("\n").map((e=>e?B(this,H,"f").repeat(B(this,K,"f"))+e.trimEnd():""));return B(this,U,"f").push(...t),this}startBlock(){var e;return D(this,K,(e=B(this,K,"f"),++e),"f"),this}endBlock(){var e;return D(this,K,(e=B(this,K,"f"),--e),"f"),this}toString(){return B(this,U,"f").join("\n")+"\n"}getIndent(){return B(this,H,"f")}getSize(){return B(this,U,"f").length}}function X(e,t){const n=[];return J(e,n,1,t),n.join("")}function J(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(z(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let a=0;a<e.length;a++)t.push(r.repeat(n)),J(e[a],t,n+1,r),a!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const a=Object.keys(e);for(let i=0;i<a.length;i++){const o=a[i],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),J(s,t,n+1,r),i!==a.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}H=new WeakMap,K=new WeakMap,U=new WeakMap;const Y=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),_=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),z=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(_.has(n))return _.get(n);return"\\x"+Y(n.charCodeAt(0),2)}if(r){return"\\u"+Y(r.charCodeAt(0),4)}return t?_.get(t)||"":e};let a="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",a=e.replace(n,r)):(i="`",a=e.replace(t,r)):(i='"',a=e.replace(t,r)):(i="'",a=e.replace(t,r)),`${i}${a}${i}`};var G,Q,Z,ee,te,ne,re,ae,ie,oe,se,le,ce,ue,pe,fe,we,de,he;class me extends R{constructor(){super(...arguments),G.add(this)}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v13.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||ye};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine("")}async afterAllSteps(e,t){e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine("");for(const t of ge.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),B(this,G,"m",ee).call(this,e,t),t.assertedEvents){e.appendLine("const promises = [];");for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}}B(this,G,"m",fe).call(this,e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}}G=new WeakSet,Q=function(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${X(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))},Z=function(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)},ee=function(e,t){B(this,G,"m",Q).call(this,e,t.target||"main"),t.frame&&B(this,G,"m",Z).call(this,e,t.frame)},te=function(e,t){e.appendLine(`await scrollIntoViewIfNeeded(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`),e.appendLine(`const element = await waitForSelectors(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, { timeout, visible: true });`)},ne=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},re=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});"),e.appendLine("await element.click({"),e.appendLine(" clickCount: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},ae=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.hover();")},ie=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("const inputType = await element.evaluate(el => el.type);"),e.appendLine("if (inputType === 'select-one') {"),e.appendLine(` await changeSelectElement(element, ${X(t.value,e.getIndent())})`),e.appendLine(`} else if (${X(Array.from(i),e.getIndent())}.includes(inputType)) {`),e.appendLine(` await typeIntoElement(element, ${X(t.value,e.getIndent())});`),e.appendLine("} else {"),e.appendLine(` await changeElementValue(element, ${X(t.value,e.getIndent())});`),e.appendLine("}")},oe=function(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")},se=function(e,t){e.appendLine(`await targetPage.keyboard.down(${X(t.key,e.getIndent())});`)},le=function(e,t){e.appendLine(`await targetPage.keyboard.up(${X(t.key,e.getIndent())});`)},ce=function(e,t){e.appendLine("await targetPage.close()")},ue=function(e,t){e.appendLine(`await targetPage.setViewport(${X({width:t.width,height:t.height},e.getIndent())})`)},pe=function(e,t){"selectors"in t?(B(this,G,"m",te).call(this,e,t),e.appendLine(`await element.evaluate((el, x, y) => { el.scrollTop = y; el.scrollLeft = x; }, ${t.x}, ${t.y});`)):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)},fe=function(e,n){switch(n.type){case t.Click:return B(this,G,"m",ne).call(this,e,n);case t.DoubleClick:return B(this,G,"m",re).call(this,e,n);case t.Hover:return B(this,G,"m",ae).call(this,e,n);case t.Change:return B(this,G,"m",ie).call(this,e,n);case t.EmulateNetworkConditions:return B(this,G,"m",oe).call(this,e,n);case t.KeyDown:return B(this,G,"m",se).call(this,e,n);case t.KeyUp:return B(this,G,"m",le).call(this,e,n);case t.Close:return B(this,G,"m",ce).call(this,e,n);case t.SetViewport:return B(this,G,"m",ue).call(this,e,n);case t.Scroll:return B(this,G,"m",pe).call(this,e,n);case t.Navigate:return B(this,G,"m",we).call(this,e,n);case t.WaitForElement:return B(this,G,"m",he).call(this,e,n);case t.WaitForExpression:return B(this,G,"m",de).call(this,e,n);case t.CustomStep:return;default:return a(n)}},we=function(e,t){e.appendLine(`await targetPage.goto(${X(t.url,e.getIndent())});`)},de=function(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${X(t.expression,e.getIndent())}, { timeout });`)},he=function(e,t){e.appendLine(`await waitForElement(${X(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)};const ye=5e3,ge="async function waitForSelectors(selectors, frame, options) {\n for (const selector of selectors) {\n try {\n return await waitForSelector(selector, frame, options);\n } catch (err) {\n console.error(err);\n }\n }\n throw new Error('Could not find element for selectors: ' + JSON.stringify(selectors));\n}\n\nasync function scrollIntoViewIfNeeded(selectors, frame, timeout) {\n const element = await waitForSelectors(selectors, frame, { visible: false, timeout });\n if (!element) {\n throw new Error(\n 'The element could not be found.'\n );\n }\n await waitForConnected(element, timeout);\n const isInViewport = await element.isIntersectingViewport({threshold: 0});\n if (isInViewport) {\n return;\n }\n await element.evaluate(element => {\n element.scrollIntoView({\n block: 'center',\n inline: 'center',\n behavior: 'auto',\n });\n });\n await waitForInViewport(element, timeout);\n}\n\nasync function waitForConnected(element, timeout) {\n await waitForFunction(async () => {\n return await element.getProperty('isConnected');\n }, timeout);\n}\n\nasync function waitForInViewport(element, timeout) {\n await waitForFunction(async () => {\n return await element.isIntersectingViewport({threshold: 0});\n }, timeout);\n}\n\nasync function waitForSelector(selector, frame, options) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to waitForSelector');\n }\n let element = null;\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (element) {\n element = await element.waitForSelector(part, options);\n } else {\n element = await frame.waitForSelector(part, options);\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('>>'));\n }\n if (i < selector.length - 1) {\n element = (await element.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n }\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('|'));\n }\n return element;\n}\n\nasync function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}\n\nasync function changeSelectElement(element, value) {\n await element.select(value);\n await element.evaluateHandle((e) => {\n e.blur();\n e.focus();\n });\n}\n\nasync function changeElementValue(element, value) {\n await element.focus();\n await element.evaluate((input, value) => {\n input.value = value;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n }, value);\n}\n\nasync function typeIntoElement(element, value) {\n const textToType = await element.evaluate((input, newValue) => {\n if (\n newValue.length <= input.value.length ||\n !newValue.startsWith(input.value)\n ) {\n input.value = '';\n return newValue;\n }\n const originalValue = input.value;\n input.value = '';\n input.value = originalValue;\n return newValue.substring(originalValue.length);\n }, value);\n await element.type(textToType);\n}",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",be=ve.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map);function Ee(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>2147483647)throw new Error("Only integers between 0 and 2147483647 are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(ve[n])}while(0!==e);return t.join("")}function Se(e){const t=[],n=e.split("");let r=0,a=0;for(const e of n){const n=be.get(e);r|=(31&n)<<a,a+=5;32&n||(t.push(r),r=0,a=0)}return t}async function Le(e,t){var n,r,a,i,o,s,l;t||(t={});const c=null!==(n=t.extension)&&void 0!==n?n:new me,u=null!==(r=t.writer)&&void 0!==r?r:new q(null!==(a=t.indentation)&&void 0!==a?a:" ");await(null===(i=c.beforeAllSteps)||void 0===i?void 0:i.call(c,u,e));const p=[1];for(const t of e.steps){const n=u.getSize();await(null===(o=c.beforeEachStep)||void 0===o?void 0:o.call(c,u,t,e)),await c.stringifyStep(u,t,e),await(null===(s=c.afterEachStep)||void 0===s?void 0:s.call(c,u,t,e));const r=u.getSize();p.push(n,r-n)}return await(null===(l=c.afterAllSteps)||void 0===l?void 0:l.call(c,u,e)),u.appendLine("//# recorderSourceMap="+function(e){const t=[];for(const n of e)t.push(Ee(n));return t.join("")}(p)),u.toString()}async function ke(e,t){var n,r,a,i;t||(t={});let o=t.extension;o||(o=new me),t.indentation||(t.indentation=" ");const s=null!==(n=t.writer)&&void 0!==n?n:new q(null!==(r=t.indentation)&&void 0!==r?r:" ");return await(null===(a=o.beforeEachStep)||void 0===a?void 0:a.call(o,s,e)),await o.stringifyStep(s,e),await(null===(i=o.afterEachStep)||void 0===i?void 0:i.call(o,s,e)),s.toString()}function Fe(e){return e.trim().startsWith("//# recorderSourceMap=")}function Ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(Fe(n))return Se(n.trim().substring("//# recorderSourceMap=".length))}}function Ce(e){return e.split("\n").filter((e=>!Fe(e))).join("\n")}class $e{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}var xe,Te,Ie;const Ne={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};class Ve extends $e{constructor(e,t,n){super(),xe.add(this),this.browser=e,this.page=t,this.timeout=(null==n?void 0:n.timeout)||5e3}async runStep(e,t){const n=B(this,xe,"m",Ie).call(this,e,t),r=this.page,a=this.browser,i=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const a=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),i=await a.page();if(!i)return null;return i.setDefaultTimeout(r),i}(a,r,e,n);let o=null;if(!i&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||i;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await B(this,xe,"m",Te).call(this,s);const l=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,l,n)}async runStepInFrame(e,r,o,l,c){const u=!0;let p=null;const f=()=>{p=async function(e,t,r){const a=[];if(t.assertedEvents)for(const i of t.assertedEvents){if(i.type!==n.Navigation)throw new Error(`Event type ${i.type} is not supported`);a.push(e.waitForNavigation({timeout:r}))}await Promise.all(a)}(l,e,c)};switch(e.type){case t.DoubleClick:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.click({clickCount:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Click:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Hover:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.hover(),await t.dispose()}break;case t.EmulateNetworkConditions:f(),await r.emulateNetworkConditions(e);break;case t.KeyDown:f(),await r.keyboard.down(e.key),await r.waitForTimeout(100);break;case t.KeyUp:f(),await r.keyboard.up(e.key),await r.waitForTimeout(100);break;case t.Close:"close"in o&&(f(),await o.close());break;case t.Change:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);const n=await t.evaluate((e=>e.type));f(),"select-one"===n?await this.changeSelectElement(e,t):i.has(n)?await this.typeIntoElement(e,t):await this.changeElementValue(e,t),await t.dispose()}break;case t.SetViewport:"setViewport"in o&&(f(),await o.setViewport(e));break;case t.Scroll:if("selectors"in e){await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});f(),await t.evaluate(((e,t,n)=>{e.scrollTop=n,e.scrollLeft=t}),e.x||0,e.y||0),await t.dispose()}else f(),await l.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0);break;case t.Navigate:f(),await l.goto(e.url);break;case t.WaitForElement:try{f(),await async function(e,t,n){const{count:r=1,operator:a=">=",visible:i=!0,properties:o,attributes:s}=e,l=Ne[a];await Me((async()=>{const n=await async function(e,t){for(const n of e){const e=await Re(n,t);if(e.length)return e}return[]}(e.selectors,t);let a=l(n.length,r);const c=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),a&&(o||s)&&(a=await c.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,a]of Object.entries(e))if(!r(a,t[n]))return!1;return!0}}),o,s)),await c.dispose(),a===i}),n)}(e,l,c)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:f(),await l.waitForFunction(e.expression,{timeout:c});break;case t.CustomStep:break;default:a(e)}await p}async typeIntoElement(e,t){const n=await t.evaluate(((e,t)=>{if(t.length<=e.value.length||!t.startsWith(e.value))return e.value="",t;const n=e.value;return e.value="",e.value=n,t.substring(n.length)}),e.value);await t.type(n)}async changeElementValue(e,t){await t.focus(),await t.evaluate(((e,t)=>{e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}),e.value)}async changeSelectElement(e,t){await t.select(e.value),await t.evaluateHandle((e=>{e.blur(),e.focus()}))}}xe=new WeakSet,Te=async function(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}},Ie=function(e,t){return e.timeout||(null==t?void 0:t.timeout)||this.timeout};class je extends Ve{async afterAllSteps(){await this.browser.close()}}async function Pe(e,t,n){const r=await We(e,t,{visible:!1,timeout:n});if(!r)throw new Error("The element could not be found.");await async function(e,t){await Me((async()=>await e.evaluate((e=>e.isConnected))),t)}(r,n);const a=await(async e=>await e.evaluate((e=>e instanceof SVGElement))?e:null)(r),i=a?await async function(e){return await e.evaluateHandle((e=>{var t;return null!==(t=e.ownerSVGElement)&&void 0!==t?t:e}))}(a):r;!!i&&await i.isIntersectingViewport({threshold:0})||(await async function(e){await e.evaluate((e=>{e.scrollIntoView({block:"center",inline:"center",behavior:"auto"})}))}(r),i&&await async function(e,t){await Me((async()=>await e.isIntersectingViewport({threshold:0})),t)}(i,n),await i.dispose(),i!==r&&await r.dispose())}async function We(e,t,n){for(const r of e)try{return await Oe(r,t,n)}catch(e){console.error("error in waitForSelectors",e)}throw new Error("Could not find element for selectors: "+JSON.stringify(e))}async function Oe(e,t,n){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to `waitForSelector`");let r=1===e.length,a=await t.waitForSelector(e[0],{...n,visible:r&&n.visible});for(const t of e.slice(1,e.length)){if(!a)throw new Error("Could not find element: "+e.join(">>"));const i=await a.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e));a.dispose(),r=e[e.length-1]===t,a=await i.waitForSelector(t,{...n,visible:r&&n.visible}),i.dispose()}if(!a)throw new Error("Could not find element: "+e.join(">>"));return a}async function Re(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function Me(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}var Be,De,He,Ke,Ue,qe,Xe;async function Je(e,t,n){var r,a;await(null===(r=e.beforeEachStep)||void 0===r?void 0:r.call(e,t,n)),await e.runStep(t,n),await(null===(a=e.afterEachStep)||void 0===a?void 0:a.call(e,t,n))}class Ye{constructor(e){Be.set(this,void 0),De.set(this,void 0),He.set(this,!1),D(this,De,e,"f")}abort(){D(this,He,!0,"f")}set flow(e){D(this,Be,e,"f")}async runBeforeAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).beforeAllSteps)||void 0===n?void 0:n.call(t,e))}async runAfterAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).afterAllSteps)||void 0===n?void 0:n.call(t,e))}async runStep(e){await Je(B(this,De,"f"),e)}async run(){var e,t,n,r,a,i;if(!B(this,Be,"f"))throw new Error("Set the flow on the runner instance before calling `run`.");const o=B(this,Be,"f");if(D(this,He,!1,"f"),await(null===(t=(e=B(this,De,"f")).beforeAllSteps)||void 0===t?void 0:t.call(e,o)),B(this,He,"f"))return!1;for(const e of o.steps){if(B(this,He,"f"))return await(null===(r=(n=B(this,De,"f")).afterAllSteps)||void 0===r?void 0:r.call(n,o)),!1;await Je(B(this,De,"f"),e,o)}return await(null===(i=(a=B(this,De,"f")).afterAllSteps)||void 0===i?void 0:i.call(a,o)),!0}}async function _e(e,t){const n=e instanceof $e?e:t,r=e instanceof $e?void 0:e,a=new Ye(null!=n?n:await async function(){const{default:e}=await import("puppeteer"),t=await e.launch({headless:!0}),n=await t.newPage();return new je(t,n)}());return r&&(a.flow=r),a}Be=new WeakMap,De=new WeakMap,He=new WeakMap;class ze extends R{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${X(t,e.getIndent())});`)}}function Ge(e){var r;return Boolean(e.type===t.Navigate||(null===(r=e.assertedEvents)||void 0===r?void 0:r.some((e=>e.type===n.Navigation))))}function Qe(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ze extends me{constructor(){super(...arguments),Ke.set(this,!1)}async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${X({screenEmulation:{disabled:!0}},e.getIndent())}`),Qe(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${X(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const a=Ge(n);a?(B(this,Ke,"f")&&(e.appendLine("await lhFlow.endTimespan();"),D(this,Ke,!1,"f")),e.appendLine("await lhFlow.startNavigation();")):B(this,Ke,"f")||(e.appendLine("await lhFlow.startTimespan();"),D(this,Ke,!0,"f")),await super.stringifyStep(e,n,r),a&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){B(this,Ke,"f")&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}Ke=new WeakMap;class et extends Ve{constructor(){super(...arguments),Ue.set(this,!1),qe.set(this,!1),Xe.set(this,void 0)}async createFlowResult(){if(!B(this,Xe,"f"))throw new Error("Cannot get flow result before running the flow");return B(this,Xe,"f").createFlowResult()}async beforeAllSteps(e){var t;await(null===(t=super.beforeAllSteps)||void 0===t?void 0:t.call(this,e));const{startFlow:n,desktopConfig:r}=await import("lighthouse");let a;Qe(e)||(a=r),D(this,Xe,await n(this.page,{config:a,flags:{screenEmulation:{disabled:!0}},name:e.title}),"f")}async beforeEachStep(e,n){var r;await(null===(r=super.beforeEachStep)||void 0===r?void 0:r.call(this,e,n)),e.type!==t.SetViewport&&(Ge(e)?(B(this,Ue,"f")&&(await B(this,Xe,"f").endTimespan(),D(this,Ue,!1,"f")),await B(this,Xe,"f").startNavigation(),D(this,qe,!0,"f")):B(this,Ue,"f")||(await B(this,Xe,"f").startTimespan(),D(this,Ue,!0,"f")))}async afterEachStep(e,t){var n;B(this,qe,"f")&&(await B(this,Xe,"f").endNavigation(),D(this,qe,!1,"f")),await(null===(n=super.afterEachStep)||void 0===n?void 0:n.call(this,e,t))}async afterAllSteps(e){var t;B(this,Ue,"f")&&await B(this,Xe,"f").endTimespan(),await(null===(t=super.afterAllSteps)||void 0===t?void 0:t.call(this,e))}}Ue=new WeakMap,qe=new WeakMap,Xe=new WeakMap;export{n as AssertedEventType,M as JSONStringifyExtension,et as LighthouseRunnerExtension,Ze as LighthouseStringifyExtension,ze as PuppeteerReplayStringifyExtension,Ve as PuppeteerRunnerExtension,je as PuppeteerRunnerOwningBrowserExtension,me as PuppeteerStringifyExtension,Ye as Runner,$e as RunnerExtension,r as Schema,e as SelectorType,t as StepType,R as StringifyExtension,a as assertAllStepTypesAreHandled,_e as createRunner,z as formatAsJSLiteral,X as formatJSONAsJS,O as getSelectorType,V as maxTimeout,N as minTimeout,s as mouseButtonMap,W as parse,Ae as parseSourceMap,T as parseStep,o as pointerDeviceTypes,Le as stringify,ke as stringifyStep,Ce as stripSourceMap,i as typeableInputTypes,P as validTimeout};
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout};

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High library

This does not escape backslash characters in the input.
@@ -1 +1 @@
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e=e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t=t||(t={})),function(e){e.Navigation="navigation"}(n=n||(n={}));var r=Object.freeze({__proto__:null,get SelectorType(){return e},get StepType(){return t},get AssertedEventType(){return n}});function a(e){throw new Error(`Unknown step type: ${e.type}`)}const i=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function l(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function c(e){return"object"==typeof e&&null!==e}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function w(e){if(l(e,"target")&&u(e.target))return e.target}function d(e){if(l(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(l(e,t)){const n=e[t];if(p(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(l(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function y(e,t){if(l(e,t))return h(e,t)}function g(e,t){if(l(e,t))return b(e,t)}function v(e,t){if(l(e,t))return m(e,t)}function b(e,t){if(l(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!l(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!u(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!u(e))throw new Error("Selector element is not a string");return e})):e}))}function S(e){if(l(e,"selectors"))return E(e)}function L(e){if(!c(e))throw new Error("Asserted event is not an object");if(!l(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:g(e,"url"),title:g(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(l(t,"timeout")&&p(t.timeout)&&!P(t.timeout))throw new Error(j);return{type:e,assertedEvents:l(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:l(t,"timeout")&&p(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:w(t)}}function C(e,t){return{...A(e,t),frame:d(t)}}function $(e,t){return{...C(e,t),selectors:E(t)}}function x(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:y(e,"duration")},n=g(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const a=g(e,"button");if(a){if(!function(e){return"string"==typeof e&&s.has(e)}(a))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=a}return t}function T(e,n){if(!c(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!l(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!u(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...$(t.Click,e),...x(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...$(t.DoubleClick,e),...x(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...$(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...$(t.Change,e),type:t.Change,value:b(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:b(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:b(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...C(t.Scroll,e),type:t.Scroll,x:y(e,"x"),y:y(e,"y"),selectors:S(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:w(e),url:b(e,"url")}}(e);case t.CustomStep:return function(e){if(!l(e,"name"))throw new Error("customStep is missing name");if(!u(e.name))throw new Error("customStep's name is not a string");return{...C(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:l(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=g(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(l(e,"attributes")&&(!c(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(l(e,"properties")&&!c(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...$(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:y(e,"count"),visible:v(e,"visible"),attributes:l(e,"attributes")?e.attributes:void 0,properties:l(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!l(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...C(t.WaitForExpression,e),type:t.WaitForExpression,expression:b(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function I(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push(T(r,n));return t}const N=1,V=3e4,j="Timeout is not between 1 and 30000 milliseconds";function P(e){return e>=1&&e<=3e4}function W(e){if(!c(e))throw new Error("Recording is not an object");if(!l(e,"title"))throw new Error("Recording is missing `title`");if(!u(e.title))throw new Error("Recording `title` is not a string");if(l(e,"timeout")&&!p(e.timeout))throw new Error("Recording `timeout` is not a number");if(!l(e,"steps"))throw new Error("Recording is missing `steps`");if(l(e,"timeout")&&p(e.timeout)&&!P(e.timeout))throw new Error(j);return t={title:e.title,timeout:l(e,"timeout")&&p(e.timeout)?e.timeout:void 0,selectorAttribute:l(e,"selectorAttribute")&&u(e.selectorAttribute)?e.selectorAttribute:void 0,steps:I(e.steps)},JSON.parse(JSON.stringify(t));var t}function O(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}class R{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class M extends R{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const a=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+a)}}function B(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function D(e,t,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(e,n):a?a.value=n:t.set(e,n),n}var H,K,U;class q{constructor(e){H.set(this,void 0),K.set(this,0),U.set(this,[]),D(this,H,e,"f")}appendLine(e){const t=e.split("\n").map((e=>e?B(this,H,"f").repeat(B(this,K,"f"))+e.trimEnd():""));return B(this,U,"f").push(...t),this}startBlock(){var e;return D(this,K,(e=B(this,K,"f"),++e),"f"),this}endBlock(){var e;return D(this,K,(e=B(this,K,"f"),--e),"f"),this}toString(){return B(this,U,"f").join("\n")+"\n"}getIndent(){return B(this,H,"f")}getSize(){return B(this,U,"f").length}}function X(e,t){const n=[];return J(e,n,1,t),n.join("")}function J(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(z(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let a=0;a<e.length;a++)t.push(r.repeat(n)),J(e[a],t,n+1,r),a!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const a=Object.keys(e);for(let i=0;i<a.length;i++){const o=a[i],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),J(s,t,n+1,r),i!==a.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}H=new WeakMap,K=new WeakMap,U=new WeakMap;const Y=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),_=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),z=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(_.has(n))return _.get(n);return"\\x"+Y(n.charCodeAt(0),2)}if(r){return"\\u"+Y(r.charCodeAt(0),4)}return t?_.get(t)||"":e};let a="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",a=e.replace(n,r)):(i="`",a=e.replace(t,r)):(i='"',a=e.replace(t,r)):(i="'",a=e.replace(t,r)),`${i}${a}${i}`};var G,Q,Z,ee,te,ne,re,ae,ie,oe,se,le,ce,ue,pe,fe,we,de,he;class me extends R{constructor(){super(...arguments),G.add(this)}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v13.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||ye};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine("")}async afterAllSteps(e,t){e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine("");for(const t of ge.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),B(this,G,"m",ee).call(this,e,t),t.assertedEvents){e.appendLine("const promises = [];");for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}}B(this,G,"m",fe).call(this,e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}}G=new WeakSet,Q=function(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${X(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))},Z=function(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)},ee=function(e,t){B(this,G,"m",Q).call(this,e,t.target||"main"),t.frame&&B(this,G,"m",Z).call(this,e,t.frame)},te=function(e,t){e.appendLine(`await scrollIntoViewIfNeeded(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`),e.appendLine(`const element = await waitForSelectors(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, { timeout, visible: true });`)},ne=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},re=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});"),e.appendLine("await element.click({"),e.appendLine(" clickCount: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},ae=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.hover();")},ie=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("const inputType = await element.evaluate(el => el.type);"),e.appendLine("if (inputType === 'select-one') {"),e.appendLine(` await changeSelectElement(element, ${X(t.value,e.getIndent())})`),e.appendLine(`} else if (${X(Array.from(i),e.getIndent())}.includes(inputType)) {`),e.appendLine(` await typeIntoElement(element, ${X(t.value,e.getIndent())});`),e.appendLine("} else {"),e.appendLine(` await changeElementValue(element, ${X(t.value,e.getIndent())});`),e.appendLine("}")},oe=function(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")},se=function(e,t){e.appendLine(`await targetPage.keyboard.down(${X(t.key,e.getIndent())});`)},le=function(e,t){e.appendLine(`await targetPage.keyboard.up(${X(t.key,e.getIndent())});`)},ce=function(e,t){e.appendLine("await targetPage.close()")},ue=function(e,t){e.appendLine(`await targetPage.setViewport(${X({width:t.width,height:t.height},e.getIndent())})`)},pe=function(e,t){"selectors"in t?(B(this,G,"m",te).call(this,e,t),e.appendLine(`await element.evaluate((el, x, y) => { el.scrollTop = y; el.scrollLeft = x; }, ${t.x}, ${t.y});`)):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)},fe=function(e,n){switch(n.type){case t.Click:return B(this,G,"m",ne).call(this,e,n);case t.DoubleClick:return B(this,G,"m",re).call(this,e,n);case t.Hover:return B(this,G,"m",ae).call(this,e,n);case t.Change:return B(this,G,"m",ie).call(this,e,n);case t.EmulateNetworkConditions:return B(this,G,"m",oe).call(this,e,n);case t.KeyDown:return B(this,G,"m",se).call(this,e,n);case t.KeyUp:return B(this,G,"m",le).call(this,e,n);case t.Close:return B(this,G,"m",ce).call(this,e,n);case t.SetViewport:return B(this,G,"m",ue).call(this,e,n);case t.Scroll:return B(this,G,"m",pe).call(this,e,n);case t.Navigate:return B(this,G,"m",we).call(this,e,n);case t.WaitForElement:return B(this,G,"m",he).call(this,e,n);case t.WaitForExpression:return B(this,G,"m",de).call(this,e,n);case t.CustomStep:return;default:return a(n)}},we=function(e,t){e.appendLine(`await targetPage.goto(${X(t.url,e.getIndent())});`)},de=function(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${X(t.expression,e.getIndent())}, { timeout });`)},he=function(e,t){e.appendLine(`await waitForElement(${X(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)};const ye=5e3,ge="async function waitForSelectors(selectors, frame, options) {\n for (const selector of selectors) {\n try {\n return await waitForSelector(selector, frame, options);\n } catch (err) {\n console.error(err);\n }\n }\n throw new Error('Could not find element for selectors: ' + JSON.stringify(selectors));\n}\n\nasync function scrollIntoViewIfNeeded(selectors, frame, timeout) {\n const element = await waitForSelectors(selectors, frame, { visible: false, timeout });\n if (!element) {\n throw new Error(\n 'The element could not be found.'\n );\n }\n await waitForConnected(element, timeout);\n const isInViewport = await element.isIntersectingViewport({threshold: 0});\n if (isInViewport) {\n return;\n }\n await element.evaluate(element => {\n element.scrollIntoView({\n block: 'center',\n inline: 'center',\n behavior: 'auto',\n });\n });\n await waitForInViewport(element, timeout);\n}\n\nasync function waitForConnected(element, timeout) {\n await waitForFunction(async () => {\n return await element.getProperty('isConnected');\n }, timeout);\n}\n\nasync function waitForInViewport(element, timeout) {\n await waitForFunction(async () => {\n return await element.isIntersectingViewport({threshold: 0});\n }, timeout);\n}\n\nasync function waitForSelector(selector, frame, options) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to waitForSelector');\n }\n let element = null;\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (element) {\n element = await element.waitForSelector(part, options);\n } else {\n element = await frame.waitForSelector(part, options);\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('>>'));\n }\n if (i < selector.length - 1) {\n element = (await element.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n }\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('|'));\n }\n return element;\n}\n\nasync function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}\n\nasync function changeSelectElement(element, value) {\n await element.select(value);\n await element.evaluateHandle((e) => {\n e.blur();\n e.focus();\n });\n}\n\nasync function changeElementValue(element, value) {\n await element.focus();\n await element.evaluate((input, value) => {\n input.value = value;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n }, value);\n}\n\nasync function typeIntoElement(element, value) {\n const textToType = await element.evaluate((input, newValue) => {\n if (\n newValue.length <= input.value.length ||\n !newValue.startsWith(input.value)\n ) {\n input.value = '';\n return newValue;\n }\n const originalValue = input.value;\n input.value = '';\n input.value = originalValue;\n return newValue.substring(originalValue.length);\n }, value);\n await element.type(textToType);\n}",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",be=ve.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map);function Ee(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>2147483647)throw new Error("Only integers between 0 and 2147483647 are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(ve[n])}while(0!==e);return t.join("")}function Se(e){const t=[],n=e.split("");let r=0,a=0;for(const e of n){const n=be.get(e);r|=(31&n)<<a,a+=5;32&n||(t.push(r),r=0,a=0)}return t}async function Le(e,t){var n,r,a,i,o,s,l;t||(t={});const c=null!==(n=t.extension)&&void 0!==n?n:new me,u=null!==(r=t.writer)&&void 0!==r?r:new q(null!==(a=t.indentation)&&void 0!==a?a:" ");await(null===(i=c.beforeAllSteps)||void 0===i?void 0:i.call(c,u,e));const p=[1];for(const t of e.steps){const n=u.getSize();await(null===(o=c.beforeEachStep)||void 0===o?void 0:o.call(c,u,t,e)),await c.stringifyStep(u,t,e),await(null===(s=c.afterEachStep)||void 0===s?void 0:s.call(c,u,t,e));const r=u.getSize();p.push(n,r-n)}return await(null===(l=c.afterAllSteps)||void 0===l?void 0:l.call(c,u,e)),u.appendLine("//# recorderSourceMap="+function(e){const t=[];for(const n of e)t.push(Ee(n));return t.join("")}(p)),u.toString()}async function ke(e,t){var n,r,a,i;t||(t={});let o=t.extension;o||(o=new me),t.indentation||(t.indentation=" ");const s=null!==(n=t.writer)&&void 0!==n?n:new q(null!==(r=t.indentation)&&void 0!==r?r:" ");return await(null===(a=o.beforeEachStep)||void 0===a?void 0:a.call(o,s,e)),await o.stringifyStep(s,e),await(null===(i=o.afterEachStep)||void 0===i?void 0:i.call(o,s,e)),s.toString()}function Fe(e){return e.trim().startsWith("//# recorderSourceMap=")}function Ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(Fe(n))return Se(n.trim().substring("//# recorderSourceMap=".length))}}function Ce(e){return e.split("\n").filter((e=>!Fe(e))).join("\n")}class $e{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}var xe,Te,Ie;const Ne={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};class Ve extends $e{constructor(e,t,n){super(),xe.add(this),this.browser=e,this.page=t,this.timeout=(null==n?void 0:n.timeout)||5e3}async runStep(e,t){const n=B(this,xe,"m",Ie).call(this,e,t),r=this.page,a=this.browser,i=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const a=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),i=await a.page();if(!i)return null;return i.setDefaultTimeout(r),i}(a,r,e,n);let o=null;if(!i&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||i;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await B(this,xe,"m",Te).call(this,s);const l=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,l,n)}async runStepInFrame(e,r,o,l,c){const u=!0;let p=null;const f=()=>{p=async function(e,t,r){const a=[];if(t.assertedEvents)for(const i of t.assertedEvents){if(i.type!==n.Navigation)throw new Error(`Event type ${i.type} is not supported`);a.push(e.waitForNavigation({timeout:r}))}await Promise.all(a)}(l,e,c)};switch(e.type){case t.DoubleClick:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.click({clickCount:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Click:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Hover:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.hover(),await t.dispose()}break;case t.EmulateNetworkConditions:f(),await r.emulateNetworkConditions(e);break;case t.KeyDown:f(),await r.keyboard.down(e.key),await r.waitForTimeout(100);break;case t.KeyUp:f(),await r.keyboard.up(e.key),await r.waitForTimeout(100);break;case t.Close:"close"in o&&(f(),await o.close());break;case t.Change:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);const n=await t.evaluate((e=>e.type));f(),"select-one"===n?await this.changeSelectElement(e,t):i.has(n)?await this.typeIntoElement(e,t):await this.changeElementValue(e,t),await t.dispose()}break;case t.SetViewport:"setViewport"in o&&(f(),await o.setViewport(e));break;case t.Scroll:if("selectors"in e){await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});f(),await t.evaluate(((e,t,n)=>{e.scrollTop=n,e.scrollLeft=t}),e.x||0,e.y||0),await t.dispose()}else f(),await l.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0);break;case t.Navigate:f(),await l.goto(e.url);break;case t.WaitForElement:try{f(),await async function(e,t,n){const{count:r=1,operator:a=">=",visible:i=!0,properties:o,attributes:s}=e,l=Ne[a];await Me((async()=>{const n=await async function(e,t){for(const n of e){const e=await Re(n,t);if(e.length)return e}return[]}(e.selectors,t);let a=l(n.length,r);const c=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),a&&(o||s)&&(a=await c.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,a]of Object.entries(e))if(!r(a,t[n]))return!1;return!0}}),o,s)),await c.dispose(),a===i}),n)}(e,l,c)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:f(),await l.waitForFunction(e.expression,{timeout:c});break;case t.CustomStep:break;default:a(e)}await p}async typeIntoElement(e,t){const n=await t.evaluate(((e,t)=>{if(t.length<=e.value.length||!t.startsWith(e.value))return e.value="",t;const n=e.value;return e.value="",e.value=n,t.substring(n.length)}),e.value);await t.type(n)}async changeElementValue(e,t){await t.focus(),await t.evaluate(((e,t)=>{e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}),e.value)}async changeSelectElement(e,t){await t.select(e.value),await t.evaluateHandle((e=>{e.blur(),e.focus()}))}}xe=new WeakSet,Te=async function(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}},Ie=function(e,t){return e.timeout||(null==t?void 0:t.timeout)||this.timeout};class je extends Ve{async afterAllSteps(){await this.browser.close()}}async function Pe(e,t,n){const r=await We(e,t,{visible:!1,timeout:n});if(!r)throw new Error("The element could not be found.");await async function(e,t){await Me((async()=>await e.evaluate((e=>e.isConnected))),t)}(r,n);const a=await(async e=>await e.evaluate((e=>e instanceof SVGElement))?e:null)(r),i=a?await async function(e){return await e.evaluateHandle((e=>{var t;return null!==(t=e.ownerSVGElement)&&void 0!==t?t:e}))}(a):r;!!i&&await i.isIntersectingViewport({threshold:0})||(await async function(e){await e.evaluate((e=>{e.scrollIntoView({block:"center",inline:"center",behavior:"auto"})}))}(r),i&&await async function(e,t){await Me((async()=>await e.isIntersectingViewport({threshold:0})),t)}(i,n),await i.dispose(),i!==r&&await r.dispose())}async function We(e,t,n){for(const r of e)try{return await Oe(r,t,n)}catch(e){console.error("error in waitForSelectors",e)}throw new Error("Could not find element for selectors: "+JSON.stringify(e))}async function Oe(e,t,n){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to `waitForSelector`");let r=1===e.length,a=await t.waitForSelector(e[0],{...n,visible:r&&n.visible});for(const t of e.slice(1,e.length)){if(!a)throw new Error("Could not find element: "+e.join(">>"));const i=await a.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e));a.dispose(),r=e[e.length-1]===t,a=await i.waitForSelector(t,{...n,visible:r&&n.visible}),i.dispose()}if(!a)throw new Error("Could not find element: "+e.join(">>"));return a}async function Re(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function Me(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}var Be,De,He,Ke,Ue,qe,Xe;async function Je(e,t,n){var r,a;await(null===(r=e.beforeEachStep)||void 0===r?void 0:r.call(e,t,n)),await e.runStep(t,n),await(null===(a=e.afterEachStep)||void 0===a?void 0:a.call(e,t,n))}class Ye{constructor(e){Be.set(this,void 0),De.set(this,void 0),He.set(this,!1),D(this,De,e,"f")}abort(){D(this,He,!0,"f")}set flow(e){D(this,Be,e,"f")}async runBeforeAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).beforeAllSteps)||void 0===n?void 0:n.call(t,e))}async runAfterAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).afterAllSteps)||void 0===n?void 0:n.call(t,e))}async runStep(e){await Je(B(this,De,"f"),e)}async run(){var e,t,n,r,a,i;if(!B(this,Be,"f"))throw new Error("Set the flow on the runner instance before calling `run`.");const o=B(this,Be,"f");if(D(this,He,!1,"f"),await(null===(t=(e=B(this,De,"f")).beforeAllSteps)||void 0===t?void 0:t.call(e,o)),B(this,He,"f"))return!1;for(const e of o.steps){if(B(this,He,"f"))return await(null===(r=(n=B(this,De,"f")).afterAllSteps)||void 0===r?void 0:r.call(n,o)),!1;await Je(B(this,De,"f"),e,o)}return await(null===(i=(a=B(this,De,"f")).afterAllSteps)||void 0===i?void 0:i.call(a,o)),!0}}async function _e(e,t){const n=e instanceof $e?e:t,r=e instanceof $e?void 0:e,a=new Ye(null!=n?n:await async function(){const{default:e}=await import("puppeteer"),t=await e.launch({headless:!0}),n=await t.newPage();return new je(t,n)}());return r&&(a.flow=r),a}Be=new WeakMap,De=new WeakMap,He=new WeakMap;class ze extends R{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${X(t,e.getIndent())});`)}}function Ge(e){var r;return Boolean(e.type===t.Navigate||(null===(r=e.assertedEvents)||void 0===r?void 0:r.some((e=>e.type===n.Navigation))))}function Qe(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ze extends me{constructor(){super(...arguments),Ke.set(this,!1)}async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${X({screenEmulation:{disabled:!0}},e.getIndent())}`),Qe(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${X(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const a=Ge(n);a?(B(this,Ke,"f")&&(e.appendLine("await lhFlow.endTimespan();"),D(this,Ke,!1,"f")),e.appendLine("await lhFlow.startNavigation();")):B(this,Ke,"f")||(e.appendLine("await lhFlow.startTimespan();"),D(this,Ke,!0,"f")),await super.stringifyStep(e,n,r),a&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){B(this,Ke,"f")&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}Ke=new WeakMap;class et extends Ve{constructor(){super(...arguments),Ue.set(this,!1),qe.set(this,!1),Xe.set(this,void 0)}async createFlowResult(){if(!B(this,Xe,"f"))throw new Error("Cannot get flow result before running the flow");return B(this,Xe,"f").createFlowResult()}async beforeAllSteps(e){var t;await(null===(t=super.beforeAllSteps)||void 0===t?void 0:t.call(this,e));const{startFlow:n,desktopConfig:r}=await import("lighthouse");let a;Qe(e)||(a=r),D(this,Xe,await n(this.page,{config:a,flags:{screenEmulation:{disabled:!0}},name:e.title}),"f")}async beforeEachStep(e,n){var r;await(null===(r=super.beforeEachStep)||void 0===r?void 0:r.call(this,e,n)),e.type!==t.SetViewport&&(Ge(e)?(B(this,Ue,"f")&&(await B(this,Xe,"f").endTimespan(),D(this,Ue,!1,"f")),await B(this,Xe,"f").startNavigation(),D(this,qe,!0,"f")):B(this,Ue,"f")||(await B(this,Xe,"f").startTimespan(),D(this,Ue,!0,"f")))}async afterEachStep(e,t){var n;B(this,qe,"f")&&(await B(this,Xe,"f").endNavigation(),D(this,qe,!1,"f")),await(null===(n=super.afterEachStep)||void 0===n?void 0:n.call(this,e,t))}async afterAllSteps(e){var t;B(this,Ue,"f")&&await B(this,Xe,"f").endTimespan(),await(null===(t=super.afterAllSteps)||void 0===t?void 0:t.call(this,e))}}Ue=new WeakMap,qe=new WeakMap,Xe=new WeakMap;export{n as AssertedEventType,M as JSONStringifyExtension,et as LighthouseRunnerExtension,Ze as LighthouseStringifyExtension,ze as PuppeteerReplayStringifyExtension,Ve as PuppeteerRunnerExtension,je as PuppeteerRunnerOwningBrowserExtension,me as PuppeteerStringifyExtension,Ye as Runner,$e as RunnerExtension,r as Schema,e as SelectorType,t as StepType,R as StringifyExtension,a as assertAllStepTypesAreHandled,_e as createRunner,z as formatAsJSLiteral,X as formatJSONAsJS,O as getSelectorType,V as maxTimeout,N as minTimeout,s as mouseButtonMap,W as parse,Ae as parseSourceMap,T as parseStep,o as pointerDeviceTypes,Le as stringify,ke as stringifyStep,Ce as stripSourceMap,i as typeableInputTypes,P as validTimeout};
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout};

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High library

This string may still contain
<!--
, which may cause an HTML element injection vulnerability.
@@ -1 +1 @@
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e=e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t=t||(t={})),function(e){e.Navigation="navigation"}(n=n||(n={}));var r=Object.freeze({__proto__:null,get SelectorType(){return e},get StepType(){return t},get AssertedEventType(){return n}});function a(e){throw new Error(`Unknown step type: ${e.type}`)}const i=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function l(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function c(e){return"object"==typeof e&&null!==e}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function w(e){if(l(e,"target")&&u(e.target))return e.target}function d(e){if(l(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(l(e,t)){const n=e[t];if(p(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(l(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function y(e,t){if(l(e,t))return h(e,t)}function g(e,t){if(l(e,t))return b(e,t)}function v(e,t){if(l(e,t))return m(e,t)}function b(e,t){if(l(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!l(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!u(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!u(e))throw new Error("Selector element is not a string");return e})):e}))}function S(e){if(l(e,"selectors"))return E(e)}function L(e){if(!c(e))throw new Error("Asserted event is not an object");if(!l(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:g(e,"url"),title:g(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(l(t,"timeout")&&p(t.timeout)&&!P(t.timeout))throw new Error(j);return{type:e,assertedEvents:l(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:l(t,"timeout")&&p(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:w(t)}}function C(e,t){return{...A(e,t),frame:d(t)}}function $(e,t){return{...C(e,t),selectors:E(t)}}function x(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:y(e,"duration")},n=g(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const a=g(e,"button");if(a){if(!function(e){return"string"==typeof e&&s.has(e)}(a))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=a}return t}function T(e,n){if(!c(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!l(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!u(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...$(t.Click,e),...x(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...$(t.DoubleClick,e),...x(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...$(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...$(t.Change,e),type:t.Change,value:b(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:b(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:b(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...C(t.Scroll,e),type:t.Scroll,x:y(e,"x"),y:y(e,"y"),selectors:S(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:w(e),url:b(e,"url")}}(e);case t.CustomStep:return function(e){if(!l(e,"name"))throw new Error("customStep is missing name");if(!u(e.name))throw new Error("customStep's name is not a string");return{...C(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:l(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=g(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(l(e,"attributes")&&(!c(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(l(e,"properties")&&!c(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...$(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:y(e,"count"),visible:v(e,"visible"),attributes:l(e,"attributes")?e.attributes:void 0,properties:l(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!l(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...C(t.WaitForExpression,e),type:t.WaitForExpression,expression:b(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function I(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push(T(r,n));return t}const N=1,V=3e4,j="Timeout is not between 1 and 30000 milliseconds";function P(e){return e>=1&&e<=3e4}function W(e){if(!c(e))throw new Error("Recording is not an object");if(!l(e,"title"))throw new Error("Recording is missing `title`");if(!u(e.title))throw new Error("Recording `title` is not a string");if(l(e,"timeout")&&!p(e.timeout))throw new Error("Recording `timeout` is not a number");if(!l(e,"steps"))throw new Error("Recording is missing `steps`");if(l(e,"timeout")&&p(e.timeout)&&!P(e.timeout))throw new Error(j);return t={title:e.title,timeout:l(e,"timeout")&&p(e.timeout)?e.timeout:void 0,selectorAttribute:l(e,"selectorAttribute")&&u(e.selectorAttribute)?e.selectorAttribute:void 0,steps:I(e.steps)},JSON.parse(JSON.stringify(t));var t}function O(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}class R{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class M extends R{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const a=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+a)}}function B(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function D(e,t,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(e,n):a?a.value=n:t.set(e,n),n}var H,K,U;class q{constructor(e){H.set(this,void 0),K.set(this,0),U.set(this,[]),D(this,H,e,"f")}appendLine(e){const t=e.split("\n").map((e=>e?B(this,H,"f").repeat(B(this,K,"f"))+e.trimEnd():""));return B(this,U,"f").push(...t),this}startBlock(){var e;return D(this,K,(e=B(this,K,"f"),++e),"f"),this}endBlock(){var e;return D(this,K,(e=B(this,K,"f"),--e),"f"),this}toString(){return B(this,U,"f").join("\n")+"\n"}getIndent(){return B(this,H,"f")}getSize(){return B(this,U,"f").length}}function X(e,t){const n=[];return J(e,n,1,t),n.join("")}function J(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(z(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let a=0;a<e.length;a++)t.push(r.repeat(n)),J(e[a],t,n+1,r),a!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const a=Object.keys(e);for(let i=0;i<a.length;i++){const o=a[i],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),J(s,t,n+1,r),i!==a.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}H=new WeakMap,K=new WeakMap,U=new WeakMap;const Y=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),_=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),z=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(_.has(n))return _.get(n);return"\\x"+Y(n.charCodeAt(0),2)}if(r){return"\\u"+Y(r.charCodeAt(0),4)}return t?_.get(t)||"":e};let a="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",a=e.replace(n,r)):(i="`",a=e.replace(t,r)):(i='"',a=e.replace(t,r)):(i="'",a=e.replace(t,r)),`${i}${a}${i}`};var G,Q,Z,ee,te,ne,re,ae,ie,oe,se,le,ce,ue,pe,fe,we,de,he;class me extends R{constructor(){super(...arguments),G.add(this)}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v13.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||ye};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine("")}async afterAllSteps(e,t){e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine("");for(const t of ge.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),B(this,G,"m",ee).call(this,e,t),t.assertedEvents){e.appendLine("const promises = [];");for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}}B(this,G,"m",fe).call(this,e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}}G=new WeakSet,Q=function(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${X(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))},Z=function(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)},ee=function(e,t){B(this,G,"m",Q).call(this,e,t.target||"main"),t.frame&&B(this,G,"m",Z).call(this,e,t.frame)},te=function(e,t){e.appendLine(`await scrollIntoViewIfNeeded(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`),e.appendLine(`const element = await waitForSelectors(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, { timeout, visible: true });`)},ne=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},re=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});"),e.appendLine("await element.click({"),e.appendLine(" clickCount: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},ae=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.hover();")},ie=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("const inputType = await element.evaluate(el => el.type);"),e.appendLine("if (inputType === 'select-one') {"),e.appendLine(` await changeSelectElement(element, ${X(t.value,e.getIndent())})`),e.appendLine(`} else if (${X(Array.from(i),e.getIndent())}.includes(inputType)) {`),e.appendLine(` await typeIntoElement(element, ${X(t.value,e.getIndent())});`),e.appendLine("} else {"),e.appendLine(` await changeElementValue(element, ${X(t.value,e.getIndent())});`),e.appendLine("}")},oe=function(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")},se=function(e,t){e.appendLine(`await targetPage.keyboard.down(${X(t.key,e.getIndent())});`)},le=function(e,t){e.appendLine(`await targetPage.keyboard.up(${X(t.key,e.getIndent())});`)},ce=function(e,t){e.appendLine("await targetPage.close()")},ue=function(e,t){e.appendLine(`await targetPage.setViewport(${X({width:t.width,height:t.height},e.getIndent())})`)},pe=function(e,t){"selectors"in t?(B(this,G,"m",te).call(this,e,t),e.appendLine(`await element.evaluate((el, x, y) => { el.scrollTop = y; el.scrollLeft = x; }, ${t.x}, ${t.y});`)):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)},fe=function(e,n){switch(n.type){case t.Click:return B(this,G,"m",ne).call(this,e,n);case t.DoubleClick:return B(this,G,"m",re).call(this,e,n);case t.Hover:return B(this,G,"m",ae).call(this,e,n);case t.Change:return B(this,G,"m",ie).call(this,e,n);case t.EmulateNetworkConditions:return B(this,G,"m",oe).call(this,e,n);case t.KeyDown:return B(this,G,"m",se).call(this,e,n);case t.KeyUp:return B(this,G,"m",le).call(this,e,n);case t.Close:return B(this,G,"m",ce).call(this,e,n);case t.SetViewport:return B(this,G,"m",ue).call(this,e,n);case t.Scroll:return B(this,G,"m",pe).call(this,e,n);case t.Navigate:return B(this,G,"m",we).call(this,e,n);case t.WaitForElement:return B(this,G,"m",he).call(this,e,n);case t.WaitForExpression:return B(this,G,"m",de).call(this,e,n);case t.CustomStep:return;default:return a(n)}},we=function(e,t){e.appendLine(`await targetPage.goto(${X(t.url,e.getIndent())});`)},de=function(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${X(t.expression,e.getIndent())}, { timeout });`)},he=function(e,t){e.appendLine(`await waitForElement(${X(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)};const ye=5e3,ge="async function waitForSelectors(selectors, frame, options) {\n for (const selector of selectors) {\n try {\n return await waitForSelector(selector, frame, options);\n } catch (err) {\n console.error(err);\n }\n }\n throw new Error('Could not find element for selectors: ' + JSON.stringify(selectors));\n}\n\nasync function scrollIntoViewIfNeeded(selectors, frame, timeout) {\n const element = await waitForSelectors(selectors, frame, { visible: false, timeout });\n if (!element) {\n throw new Error(\n 'The element could not be found.'\n );\n }\n await waitForConnected(element, timeout);\n const isInViewport = await element.isIntersectingViewport({threshold: 0});\n if (isInViewport) {\n return;\n }\n await element.evaluate(element => {\n element.scrollIntoView({\n block: 'center',\n inline: 'center',\n behavior: 'auto',\n });\n });\n await waitForInViewport(element, timeout);\n}\n\nasync function waitForConnected(element, timeout) {\n await waitForFunction(async () => {\n return await element.getProperty('isConnected');\n }, timeout);\n}\n\nasync function waitForInViewport(element, timeout) {\n await waitForFunction(async () => {\n return await element.isIntersectingViewport({threshold: 0});\n }, timeout);\n}\n\nasync function waitForSelector(selector, frame, options) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to waitForSelector');\n }\n let element = null;\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (element) {\n element = await element.waitForSelector(part, options);\n } else {\n element = await frame.waitForSelector(part, options);\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('>>'));\n }\n if (i < selector.length - 1) {\n element = (await element.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n }\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('|'));\n }\n return element;\n}\n\nasync function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}\n\nasync function changeSelectElement(element, value) {\n await element.select(value);\n await element.evaluateHandle((e) => {\n e.blur();\n e.focus();\n });\n}\n\nasync function changeElementValue(element, value) {\n await element.focus();\n await element.evaluate((input, value) => {\n input.value = value;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n }, value);\n}\n\nasync function typeIntoElement(element, value) {\n const textToType = await element.evaluate((input, newValue) => {\n if (\n newValue.length <= input.value.length ||\n !newValue.startsWith(input.value)\n ) {\n input.value = '';\n return newValue;\n }\n const originalValue = input.value;\n input.value = '';\n input.value = originalValue;\n return newValue.substring(originalValue.length);\n }, value);\n await element.type(textToType);\n}",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",be=ve.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map);function Ee(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>2147483647)throw new Error("Only integers between 0 and 2147483647 are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(ve[n])}while(0!==e);return t.join("")}function Se(e){const t=[],n=e.split("");let r=0,a=0;for(const e of n){const n=be.get(e);r|=(31&n)<<a,a+=5;32&n||(t.push(r),r=0,a=0)}return t}async function Le(e,t){var n,r,a,i,o,s,l;t||(t={});const c=null!==(n=t.extension)&&void 0!==n?n:new me,u=null!==(r=t.writer)&&void 0!==r?r:new q(null!==(a=t.indentation)&&void 0!==a?a:" ");await(null===(i=c.beforeAllSteps)||void 0===i?void 0:i.call(c,u,e));const p=[1];for(const t of e.steps){const n=u.getSize();await(null===(o=c.beforeEachStep)||void 0===o?void 0:o.call(c,u,t,e)),await c.stringifyStep(u,t,e),await(null===(s=c.afterEachStep)||void 0===s?void 0:s.call(c,u,t,e));const r=u.getSize();p.push(n,r-n)}return await(null===(l=c.afterAllSteps)||void 0===l?void 0:l.call(c,u,e)),u.appendLine("//# recorderSourceMap="+function(e){const t=[];for(const n of e)t.push(Ee(n));return t.join("")}(p)),u.toString()}async function ke(e,t){var n,r,a,i;t||(t={});let o=t.extension;o||(o=new me),t.indentation||(t.indentation=" ");const s=null!==(n=t.writer)&&void 0!==n?n:new q(null!==(r=t.indentation)&&void 0!==r?r:" ");return await(null===(a=o.beforeEachStep)||void 0===a?void 0:a.call(o,s,e)),await o.stringifyStep(s,e),await(null===(i=o.afterEachStep)||void 0===i?void 0:i.call(o,s,e)),s.toString()}function Fe(e){return e.trim().startsWith("//# recorderSourceMap=")}function Ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(Fe(n))return Se(n.trim().substring("//# recorderSourceMap=".length))}}function Ce(e){return e.split("\n").filter((e=>!Fe(e))).join("\n")}class $e{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}var xe,Te,Ie;const Ne={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};class Ve extends $e{constructor(e,t,n){super(),xe.add(this),this.browser=e,this.page=t,this.timeout=(null==n?void 0:n.timeout)||5e3}async runStep(e,t){const n=B(this,xe,"m",Ie).call(this,e,t),r=this.page,a=this.browser,i=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const a=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),i=await a.page();if(!i)return null;return i.setDefaultTimeout(r),i}(a,r,e,n);let o=null;if(!i&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||i;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await B(this,xe,"m",Te).call(this,s);const l=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,l,n)}async runStepInFrame(e,r,o,l,c){const u=!0;let p=null;const f=()=>{p=async function(e,t,r){const a=[];if(t.assertedEvents)for(const i of t.assertedEvents){if(i.type!==n.Navigation)throw new Error(`Event type ${i.type} is not supported`);a.push(e.waitForNavigation({timeout:r}))}await Promise.all(a)}(l,e,c)};switch(e.type){case t.DoubleClick:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.click({clickCount:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Click:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Hover:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.hover(),await t.dispose()}break;case t.EmulateNetworkConditions:f(),await r.emulateNetworkConditions(e);break;case t.KeyDown:f(),await r.keyboard.down(e.key),await r.waitForTimeout(100);break;case t.KeyUp:f(),await r.keyboard.up(e.key),await r.waitForTimeout(100);break;case t.Close:"close"in o&&(f(),await o.close());break;case t.Change:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);const n=await t.evaluate((e=>e.type));f(),"select-one"===n?await this.changeSelectElement(e,t):i.has(n)?await this.typeIntoElement(e,t):await this.changeElementValue(e,t),await t.dispose()}break;case t.SetViewport:"setViewport"in o&&(f(),await o.setViewport(e));break;case t.Scroll:if("selectors"in e){await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});f(),await t.evaluate(((e,t,n)=>{e.scrollTop=n,e.scrollLeft=t}),e.x||0,e.y||0),await t.dispose()}else f(),await l.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0);break;case t.Navigate:f(),await l.goto(e.url);break;case t.WaitForElement:try{f(),await async function(e,t,n){const{count:r=1,operator:a=">=",visible:i=!0,properties:o,attributes:s}=e,l=Ne[a];await Me((async()=>{const n=await async function(e,t){for(const n of e){const e=await Re(n,t);if(e.length)return e}return[]}(e.selectors,t);let a=l(n.length,r);const c=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),a&&(o||s)&&(a=await c.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,a]of Object.entries(e))if(!r(a,t[n]))return!1;return!0}}),o,s)),await c.dispose(),a===i}),n)}(e,l,c)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:f(),await l.waitForFunction(e.expression,{timeout:c});break;case t.CustomStep:break;default:a(e)}await p}async typeIntoElement(e,t){const n=await t.evaluate(((e,t)=>{if(t.length<=e.value.length||!t.startsWith(e.value))return e.value="",t;const n=e.value;return e.value="",e.value=n,t.substring(n.length)}),e.value);await t.type(n)}async changeElementValue(e,t){await t.focus(),await t.evaluate(((e,t)=>{e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}),e.value)}async changeSelectElement(e,t){await t.select(e.value),await t.evaluateHandle((e=>{e.blur(),e.focus()}))}}xe=new WeakSet,Te=async function(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}},Ie=function(e,t){return e.timeout||(null==t?void 0:t.timeout)||this.timeout};class je extends Ve{async afterAllSteps(){await this.browser.close()}}async function Pe(e,t,n){const r=await We(e,t,{visible:!1,timeout:n});if(!r)throw new Error("The element could not be found.");await async function(e,t){await Me((async()=>await e.evaluate((e=>e.isConnected))),t)}(r,n);const a=await(async e=>await e.evaluate((e=>e instanceof SVGElement))?e:null)(r),i=a?await async function(e){return await e.evaluateHandle((e=>{var t;return null!==(t=e.ownerSVGElement)&&void 0!==t?t:e}))}(a):r;!!i&&await i.isIntersectingViewport({threshold:0})||(await async function(e){await e.evaluate((e=>{e.scrollIntoView({block:"center",inline:"center",behavior:"auto"})}))}(r),i&&await async function(e,t){await Me((async()=>await e.isIntersectingViewport({threshold:0})),t)}(i,n),await i.dispose(),i!==r&&await r.dispose())}async function We(e,t,n){for(const r of e)try{return await Oe(r,t,n)}catch(e){console.error("error in waitForSelectors",e)}throw new Error("Could not find element for selectors: "+JSON.stringify(e))}async function Oe(e,t,n){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to `waitForSelector`");let r=1===e.length,a=await t.waitForSelector(e[0],{...n,visible:r&&n.visible});for(const t of e.slice(1,e.length)){if(!a)throw new Error("Could not find element: "+e.join(">>"));const i=await a.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e));a.dispose(),r=e[e.length-1]===t,a=await i.waitForSelector(t,{...n,visible:r&&n.visible}),i.dispose()}if(!a)throw new Error("Could not find element: "+e.join(">>"));return a}async function Re(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function Me(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}var Be,De,He,Ke,Ue,qe,Xe;async function Je(e,t,n){var r,a;await(null===(r=e.beforeEachStep)||void 0===r?void 0:r.call(e,t,n)),await e.runStep(t,n),await(null===(a=e.afterEachStep)||void 0===a?void 0:a.call(e,t,n))}class Ye{constructor(e){Be.set(this,void 0),De.set(this,void 0),He.set(this,!1),D(this,De,e,"f")}abort(){D(this,He,!0,"f")}set flow(e){D(this,Be,e,"f")}async runBeforeAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).beforeAllSteps)||void 0===n?void 0:n.call(t,e))}async runAfterAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).afterAllSteps)||void 0===n?void 0:n.call(t,e))}async runStep(e){await Je(B(this,De,"f"),e)}async run(){var e,t,n,r,a,i;if(!B(this,Be,"f"))throw new Error("Set the flow on the runner instance before calling `run`.");const o=B(this,Be,"f");if(D(this,He,!1,"f"),await(null===(t=(e=B(this,De,"f")).beforeAllSteps)||void 0===t?void 0:t.call(e,o)),B(this,He,"f"))return!1;for(const e of o.steps){if(B(this,He,"f"))return await(null===(r=(n=B(this,De,"f")).afterAllSteps)||void 0===r?void 0:r.call(n,o)),!1;await Je(B(this,De,"f"),e,o)}return await(null===(i=(a=B(this,De,"f")).afterAllSteps)||void 0===i?void 0:i.call(a,o)),!0}}async function _e(e,t){const n=e instanceof $e?e:t,r=e instanceof $e?void 0:e,a=new Ye(null!=n?n:await async function(){const{default:e}=await import("puppeteer"),t=await e.launch({headless:!0}),n=await t.newPage();return new je(t,n)}());return r&&(a.flow=r),a}Be=new WeakMap,De=new WeakMap,He=new WeakMap;class ze extends R{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${X(t,e.getIndent())});`)}}function Ge(e){var r;return Boolean(e.type===t.Navigate||(null===(r=e.assertedEvents)||void 0===r?void 0:r.some((e=>e.type===n.Navigation))))}function Qe(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ze extends me{constructor(){super(...arguments),Ke.set(this,!1)}async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${X({screenEmulation:{disabled:!0}},e.getIndent())}`),Qe(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${X(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const a=Ge(n);a?(B(this,Ke,"f")&&(e.appendLine("await lhFlow.endTimespan();"),D(this,Ke,!1,"f")),e.appendLine("await lhFlow.startNavigation();")):B(this,Ke,"f")||(e.appendLine("await lhFlow.startTimespan();"),D(this,Ke,!0,"f")),await super.stringifyStep(e,n,r),a&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){B(this,Ke,"f")&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}Ke=new WeakMap;class et extends Ve{constructor(){super(...arguments),Ue.set(this,!1),qe.set(this,!1),Xe.set(this,void 0)}async createFlowResult(){if(!B(this,Xe,"f"))throw new Error("Cannot get flow result before running the flow");return B(this,Xe,"f").createFlowResult()}async beforeAllSteps(e){var t;await(null===(t=super.beforeAllSteps)||void 0===t?void 0:t.call(this,e));const{startFlow:n,desktopConfig:r}=await import("lighthouse");let a;Qe(e)||(a=r),D(this,Xe,await n(this.page,{config:a,flags:{screenEmulation:{disabled:!0}},name:e.title}),"f")}async beforeEachStep(e,n){var r;await(null===(r=super.beforeEachStep)||void 0===r?void 0:r.call(this,e,n)),e.type!==t.SetViewport&&(Ge(e)?(B(this,Ue,"f")&&(await B(this,Xe,"f").endTimespan(),D(this,Ue,!1,"f")),await B(this,Xe,"f").startNavigation(),D(this,qe,!0,"f")):B(this,Ue,"f")||(await B(this,Xe,"f").startTimespan(),D(this,Ue,!0,"f")))}async afterEachStep(e,t){var n;B(this,qe,"f")&&(await B(this,Xe,"f").endNavigation(),D(this,qe,!1,"f")),await(null===(n=super.afterEachStep)||void 0===n?void 0:n.call(this,e,t))}async afterAllSteps(e){var t;B(this,Ue,"f")&&await B(this,Xe,"f").endTimespan(),await(null===(t=super.afterAllSteps)||void 0===t?void 0:t.call(this,e))}}Ue=new WeakMap,qe=new WeakMap,Xe=new WeakMap;export{n as AssertedEventType,M as JSONStringifyExtension,et as LighthouseRunnerExtension,Ze as LighthouseStringifyExtension,ze as PuppeteerReplayStringifyExtension,Ve as PuppeteerRunnerExtension,je as PuppeteerRunnerOwningBrowserExtension,me as PuppeteerStringifyExtension,Ye as Runner,$e as RunnerExtension,r as Schema,e as SelectorType,t as StepType,R as StringifyExtension,a as assertAllStepTypesAreHandled,_e as createRunner,z as formatAsJSLiteral,X as formatJSONAsJS,O as getSelectorType,V as maxTimeout,N as minTimeout,s as mouseButtonMap,W as parse,Ae as parseSourceMap,T as parseStep,o as pointerDeviceTypes,Le as stringify,ke as stringifyStep,Ce as stripSourceMap,i as typeableInputTypes,P as validTimeout};
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout};

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High library

This string may still contain
<!--
, which may cause an HTML element injection vulnerability.
@@ -1 +1 @@
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e=e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t=t||(t={})),function(e){e.Navigation="navigation"}(n=n||(n={}));var r=Object.freeze({__proto__:null,get SelectorType(){return e},get StepType(){return t},get AssertedEventType(){return n}});function a(e){throw new Error(`Unknown step type: ${e.type}`)}const i=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function l(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function c(e){return"object"==typeof e&&null!==e}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function w(e){if(l(e,"target")&&u(e.target))return e.target}function d(e){if(l(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(l(e,t)){const n=e[t];if(p(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(l(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function y(e,t){if(l(e,t))return h(e,t)}function g(e,t){if(l(e,t))return b(e,t)}function v(e,t){if(l(e,t))return m(e,t)}function b(e,t){if(l(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!l(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!u(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!u(e))throw new Error("Selector element is not a string");return e})):e}))}function S(e){if(l(e,"selectors"))return E(e)}function L(e){if(!c(e))throw new Error("Asserted event is not an object");if(!l(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:g(e,"url"),title:g(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(l(t,"timeout")&&p(t.timeout)&&!P(t.timeout))throw new Error(j);return{type:e,assertedEvents:l(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:l(t,"timeout")&&p(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:w(t)}}function C(e,t){return{...A(e,t),frame:d(t)}}function $(e,t){return{...C(e,t),selectors:E(t)}}function x(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:y(e,"duration")},n=g(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const a=g(e,"button");if(a){if(!function(e){return"string"==typeof e&&s.has(e)}(a))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=a}return t}function T(e,n){if(!c(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!l(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!u(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...$(t.Click,e),...x(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...$(t.DoubleClick,e),...x(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...$(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...$(t.Change,e),type:t.Change,value:b(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:b(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:b(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...C(t.Scroll,e),type:t.Scroll,x:y(e,"x"),y:y(e,"y"),selectors:S(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:w(e),url:b(e,"url")}}(e);case t.CustomStep:return function(e){if(!l(e,"name"))throw new Error("customStep is missing name");if(!u(e.name))throw new Error("customStep's name is not a string");return{...C(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:l(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=g(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(l(e,"attributes")&&(!c(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(l(e,"properties")&&!c(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...$(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:y(e,"count"),visible:v(e,"visible"),attributes:l(e,"attributes")?e.attributes:void 0,properties:l(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!l(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...C(t.WaitForExpression,e),type:t.WaitForExpression,expression:b(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function I(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push(T(r,n));return t}const N=1,V=3e4,j="Timeout is not between 1 and 30000 milliseconds";function P(e){return e>=1&&e<=3e4}function W(e){if(!c(e))throw new Error("Recording is not an object");if(!l(e,"title"))throw new Error("Recording is missing `title`");if(!u(e.title))throw new Error("Recording `title` is not a string");if(l(e,"timeout")&&!p(e.timeout))throw new Error("Recording `timeout` is not a number");if(!l(e,"steps"))throw new Error("Recording is missing `steps`");if(l(e,"timeout")&&p(e.timeout)&&!P(e.timeout))throw new Error(j);return t={title:e.title,timeout:l(e,"timeout")&&p(e.timeout)?e.timeout:void 0,selectorAttribute:l(e,"selectorAttribute")&&u(e.selectorAttribute)?e.selectorAttribute:void 0,steps:I(e.steps)},JSON.parse(JSON.stringify(t));var t}function O(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}class R{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class M extends R{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const a=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+a)}}function B(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function D(e,t,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(e,n):a?a.value=n:t.set(e,n),n}var H,K,U;class q{constructor(e){H.set(this,void 0),K.set(this,0),U.set(this,[]),D(this,H,e,"f")}appendLine(e){const t=e.split("\n").map((e=>e?B(this,H,"f").repeat(B(this,K,"f"))+e.trimEnd():""));return B(this,U,"f").push(...t),this}startBlock(){var e;return D(this,K,(e=B(this,K,"f"),++e),"f"),this}endBlock(){var e;return D(this,K,(e=B(this,K,"f"),--e),"f"),this}toString(){return B(this,U,"f").join("\n")+"\n"}getIndent(){return B(this,H,"f")}getSize(){return B(this,U,"f").length}}function X(e,t){const n=[];return J(e,n,1,t),n.join("")}function J(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(z(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let a=0;a<e.length;a++)t.push(r.repeat(n)),J(e[a],t,n+1,r),a!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const a=Object.keys(e);for(let i=0;i<a.length;i++){const o=a[i],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),J(s,t,n+1,r),i!==a.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}H=new WeakMap,K=new WeakMap,U=new WeakMap;const Y=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),_=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),z=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(_.has(n))return _.get(n);return"\\x"+Y(n.charCodeAt(0),2)}if(r){return"\\u"+Y(r.charCodeAt(0),4)}return t?_.get(t)||"":e};let a="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",a=e.replace(n,r)):(i="`",a=e.replace(t,r)):(i='"',a=e.replace(t,r)):(i="'",a=e.replace(t,r)),`${i}${a}${i}`};var G,Q,Z,ee,te,ne,re,ae,ie,oe,se,le,ce,ue,pe,fe,we,de,he;class me extends R{constructor(){super(...arguments),G.add(this)}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v13.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||ye};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine("")}async afterAllSteps(e,t){e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine("");for(const t of ge.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),B(this,G,"m",ee).call(this,e,t),t.assertedEvents){e.appendLine("const promises = [];");for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}}B(this,G,"m",fe).call(this,e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}}G=new WeakSet,Q=function(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${X(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))},Z=function(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)},ee=function(e,t){B(this,G,"m",Q).call(this,e,t.target||"main"),t.frame&&B(this,G,"m",Z).call(this,e,t.frame)},te=function(e,t){e.appendLine(`await scrollIntoViewIfNeeded(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`),e.appendLine(`const element = await waitForSelectors(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, { timeout, visible: true });`)},ne=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},re=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});"),e.appendLine("await element.click({"),e.appendLine(" clickCount: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},ae=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.hover();")},ie=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("const inputType = await element.evaluate(el => el.type);"),e.appendLine("if (inputType === 'select-one') {"),e.appendLine(` await changeSelectElement(element, ${X(t.value,e.getIndent())})`),e.appendLine(`} else if (${X(Array.from(i),e.getIndent())}.includes(inputType)) {`),e.appendLine(` await typeIntoElement(element, ${X(t.value,e.getIndent())});`),e.appendLine("} else {"),e.appendLine(` await changeElementValue(element, ${X(t.value,e.getIndent())});`),e.appendLine("}")},oe=function(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")},se=function(e,t){e.appendLine(`await targetPage.keyboard.down(${X(t.key,e.getIndent())});`)},le=function(e,t){e.appendLine(`await targetPage.keyboard.up(${X(t.key,e.getIndent())});`)},ce=function(e,t){e.appendLine("await targetPage.close()")},ue=function(e,t){e.appendLine(`await targetPage.setViewport(${X({width:t.width,height:t.height},e.getIndent())})`)},pe=function(e,t){"selectors"in t?(B(this,G,"m",te).call(this,e,t),e.appendLine(`await element.evaluate((el, x, y) => { el.scrollTop = y; el.scrollLeft = x; }, ${t.x}, ${t.y});`)):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)},fe=function(e,n){switch(n.type){case t.Click:return B(this,G,"m",ne).call(this,e,n);case t.DoubleClick:return B(this,G,"m",re).call(this,e,n);case t.Hover:return B(this,G,"m",ae).call(this,e,n);case t.Change:return B(this,G,"m",ie).call(this,e,n);case t.EmulateNetworkConditions:return B(this,G,"m",oe).call(this,e,n);case t.KeyDown:return B(this,G,"m",se).call(this,e,n);case t.KeyUp:return B(this,G,"m",le).call(this,e,n);case t.Close:return B(this,G,"m",ce).call(this,e,n);case t.SetViewport:return B(this,G,"m",ue).call(this,e,n);case t.Scroll:return B(this,G,"m",pe).call(this,e,n);case t.Navigate:return B(this,G,"m",we).call(this,e,n);case t.WaitForElement:return B(this,G,"m",he).call(this,e,n);case t.WaitForExpression:return B(this,G,"m",de).call(this,e,n);case t.CustomStep:return;default:return a(n)}},we=function(e,t){e.appendLine(`await targetPage.goto(${X(t.url,e.getIndent())});`)},de=function(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${X(t.expression,e.getIndent())}, { timeout });`)},he=function(e,t){e.appendLine(`await waitForElement(${X(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)};const ye=5e3,ge="async function waitForSelectors(selectors, frame, options) {\n for (const selector of selectors) {\n try {\n return await waitForSelector(selector, frame, options);\n } catch (err) {\n console.error(err);\n }\n }\n throw new Error('Could not find element for selectors: ' + JSON.stringify(selectors));\n}\n\nasync function scrollIntoViewIfNeeded(selectors, frame, timeout) {\n const element = await waitForSelectors(selectors, frame, { visible: false, timeout });\n if (!element) {\n throw new Error(\n 'The element could not be found.'\n );\n }\n await waitForConnected(element, timeout);\n const isInViewport = await element.isIntersectingViewport({threshold: 0});\n if (isInViewport) {\n return;\n }\n await element.evaluate(element => {\n element.scrollIntoView({\n block: 'center',\n inline: 'center',\n behavior: 'auto',\n });\n });\n await waitForInViewport(element, timeout);\n}\n\nasync function waitForConnected(element, timeout) {\n await waitForFunction(async () => {\n return await element.getProperty('isConnected');\n }, timeout);\n}\n\nasync function waitForInViewport(element, timeout) {\n await waitForFunction(async () => {\n return await element.isIntersectingViewport({threshold: 0});\n }, timeout);\n}\n\nasync function waitForSelector(selector, frame, options) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to waitForSelector');\n }\n let element = null;\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (element) {\n element = await element.waitForSelector(part, options);\n } else {\n element = await frame.waitForSelector(part, options);\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('>>'));\n }\n if (i < selector.length - 1) {\n element = (await element.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n }\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('|'));\n }\n return element;\n}\n\nasync function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}\n\nasync function changeSelectElement(element, value) {\n await element.select(value);\n await element.evaluateHandle((e) => {\n e.blur();\n e.focus();\n });\n}\n\nasync function changeElementValue(element, value) {\n await element.focus();\n await element.evaluate((input, value) => {\n input.value = value;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n }, value);\n}\n\nasync function typeIntoElement(element, value) {\n const textToType = await element.evaluate((input, newValue) => {\n if (\n newValue.length <= input.value.length ||\n !newValue.startsWith(input.value)\n ) {\n input.value = '';\n return newValue;\n }\n const originalValue = input.value;\n input.value = '';\n input.value = originalValue;\n return newValue.substring(originalValue.length);\n }, value);\n await element.type(textToType);\n}",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",be=ve.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map);function Ee(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>2147483647)throw new Error("Only integers between 0 and 2147483647 are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(ve[n])}while(0!==e);return t.join("")}function Se(e){const t=[],n=e.split("");let r=0,a=0;for(const e of n){const n=be.get(e);r|=(31&n)<<a,a+=5;32&n||(t.push(r),r=0,a=0)}return t}async function Le(e,t){var n,r,a,i,o,s,l;t||(t={});const c=null!==(n=t.extension)&&void 0!==n?n:new me,u=null!==(r=t.writer)&&void 0!==r?r:new q(null!==(a=t.indentation)&&void 0!==a?a:" ");await(null===(i=c.beforeAllSteps)||void 0===i?void 0:i.call(c,u,e));const p=[1];for(const t of e.steps){const n=u.getSize();await(null===(o=c.beforeEachStep)||void 0===o?void 0:o.call(c,u,t,e)),await c.stringifyStep(u,t,e),await(null===(s=c.afterEachStep)||void 0===s?void 0:s.call(c,u,t,e));const r=u.getSize();p.push(n,r-n)}return await(null===(l=c.afterAllSteps)||void 0===l?void 0:l.call(c,u,e)),u.appendLine("//# recorderSourceMap="+function(e){const t=[];for(const n of e)t.push(Ee(n));return t.join("")}(p)),u.toString()}async function ke(e,t){var n,r,a,i;t||(t={});let o=t.extension;o||(o=new me),t.indentation||(t.indentation=" ");const s=null!==(n=t.writer)&&void 0!==n?n:new q(null!==(r=t.indentation)&&void 0!==r?r:" ");return await(null===(a=o.beforeEachStep)||void 0===a?void 0:a.call(o,s,e)),await o.stringifyStep(s,e),await(null===(i=o.afterEachStep)||void 0===i?void 0:i.call(o,s,e)),s.toString()}function Fe(e){return e.trim().startsWith("//# recorderSourceMap=")}function Ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(Fe(n))return Se(n.trim().substring("//# recorderSourceMap=".length))}}function Ce(e){return e.split("\n").filter((e=>!Fe(e))).join("\n")}class $e{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}var xe,Te,Ie;const Ne={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};class Ve extends $e{constructor(e,t,n){super(),xe.add(this),this.browser=e,this.page=t,this.timeout=(null==n?void 0:n.timeout)||5e3}async runStep(e,t){const n=B(this,xe,"m",Ie).call(this,e,t),r=this.page,a=this.browser,i=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const a=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),i=await a.page();if(!i)return null;return i.setDefaultTimeout(r),i}(a,r,e,n);let o=null;if(!i&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||i;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await B(this,xe,"m",Te).call(this,s);const l=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,l,n)}async runStepInFrame(e,r,o,l,c){const u=!0;let p=null;const f=()=>{p=async function(e,t,r){const a=[];if(t.assertedEvents)for(const i of t.assertedEvents){if(i.type!==n.Navigation)throw new Error(`Event type ${i.type} is not supported`);a.push(e.waitForNavigation({timeout:r}))}await Promise.all(a)}(l,e,c)};switch(e.type){case t.DoubleClick:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.click({clickCount:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Click:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Hover:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.hover(),await t.dispose()}break;case t.EmulateNetworkConditions:f(),await r.emulateNetworkConditions(e);break;case t.KeyDown:f(),await r.keyboard.down(e.key),await r.waitForTimeout(100);break;case t.KeyUp:f(),await r.keyboard.up(e.key),await r.waitForTimeout(100);break;case t.Close:"close"in o&&(f(),await o.close());break;case t.Change:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);const n=await t.evaluate((e=>e.type));f(),"select-one"===n?await this.changeSelectElement(e,t):i.has(n)?await this.typeIntoElement(e,t):await this.changeElementValue(e,t),await t.dispose()}break;case t.SetViewport:"setViewport"in o&&(f(),await o.setViewport(e));break;case t.Scroll:if("selectors"in e){await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});f(),await t.evaluate(((e,t,n)=>{e.scrollTop=n,e.scrollLeft=t}),e.x||0,e.y||0),await t.dispose()}else f(),await l.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0);break;case t.Navigate:f(),await l.goto(e.url);break;case t.WaitForElement:try{f(),await async function(e,t,n){const{count:r=1,operator:a=">=",visible:i=!0,properties:o,attributes:s}=e,l=Ne[a];await Me((async()=>{const n=await async function(e,t){for(const n of e){const e=await Re(n,t);if(e.length)return e}return[]}(e.selectors,t);let a=l(n.length,r);const c=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),a&&(o||s)&&(a=await c.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,a]of Object.entries(e))if(!r(a,t[n]))return!1;return!0}}),o,s)),await c.dispose(),a===i}),n)}(e,l,c)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:f(),await l.waitForFunction(e.expression,{timeout:c});break;case t.CustomStep:break;default:a(e)}await p}async typeIntoElement(e,t){const n=await t.evaluate(((e,t)=>{if(t.length<=e.value.length||!t.startsWith(e.value))return e.value="",t;const n=e.value;return e.value="",e.value=n,t.substring(n.length)}),e.value);await t.type(n)}async changeElementValue(e,t){await t.focus(),await t.evaluate(((e,t)=>{e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}),e.value)}async changeSelectElement(e,t){await t.select(e.value),await t.evaluateHandle((e=>{e.blur(),e.focus()}))}}xe=new WeakSet,Te=async function(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}},Ie=function(e,t){return e.timeout||(null==t?void 0:t.timeout)||this.timeout};class je extends Ve{async afterAllSteps(){await this.browser.close()}}async function Pe(e,t,n){const r=await We(e,t,{visible:!1,timeout:n});if(!r)throw new Error("The element could not be found.");await async function(e,t){await Me((async()=>await e.evaluate((e=>e.isConnected))),t)}(r,n);const a=await(async e=>await e.evaluate((e=>e instanceof SVGElement))?e:null)(r),i=a?await async function(e){return await e.evaluateHandle((e=>{var t;return null!==(t=e.ownerSVGElement)&&void 0!==t?t:e}))}(a):r;!!i&&await i.isIntersectingViewport({threshold:0})||(await async function(e){await e.evaluate((e=>{e.scrollIntoView({block:"center",inline:"center",behavior:"auto"})}))}(r),i&&await async function(e,t){await Me((async()=>await e.isIntersectingViewport({threshold:0})),t)}(i,n),await i.dispose(),i!==r&&await r.dispose())}async function We(e,t,n){for(const r of e)try{return await Oe(r,t,n)}catch(e){console.error("error in waitForSelectors",e)}throw new Error("Could not find element for selectors: "+JSON.stringify(e))}async function Oe(e,t,n){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to `waitForSelector`");let r=1===e.length,a=await t.waitForSelector(e[0],{...n,visible:r&&n.visible});for(const t of e.slice(1,e.length)){if(!a)throw new Error("Could not find element: "+e.join(">>"));const i=await a.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e));a.dispose(),r=e[e.length-1]===t,a=await i.waitForSelector(t,{...n,visible:r&&n.visible}),i.dispose()}if(!a)throw new Error("Could not find element: "+e.join(">>"));return a}async function Re(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function Me(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}var Be,De,He,Ke,Ue,qe,Xe;async function Je(e,t,n){var r,a;await(null===(r=e.beforeEachStep)||void 0===r?void 0:r.call(e,t,n)),await e.runStep(t,n),await(null===(a=e.afterEachStep)||void 0===a?void 0:a.call(e,t,n))}class Ye{constructor(e){Be.set(this,void 0),De.set(this,void 0),He.set(this,!1),D(this,De,e,"f")}abort(){D(this,He,!0,"f")}set flow(e){D(this,Be,e,"f")}async runBeforeAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).beforeAllSteps)||void 0===n?void 0:n.call(t,e))}async runAfterAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).afterAllSteps)||void 0===n?void 0:n.call(t,e))}async runStep(e){await Je(B(this,De,"f"),e)}async run(){var e,t,n,r,a,i;if(!B(this,Be,"f"))throw new Error("Set the flow on the runner instance before calling `run`.");const o=B(this,Be,"f");if(D(this,He,!1,"f"),await(null===(t=(e=B(this,De,"f")).beforeAllSteps)||void 0===t?void 0:t.call(e,o)),B(this,He,"f"))return!1;for(const e of o.steps){if(B(this,He,"f"))return await(null===(r=(n=B(this,De,"f")).afterAllSteps)||void 0===r?void 0:r.call(n,o)),!1;await Je(B(this,De,"f"),e,o)}return await(null===(i=(a=B(this,De,"f")).afterAllSteps)||void 0===i?void 0:i.call(a,o)),!0}}async function _e(e,t){const n=e instanceof $e?e:t,r=e instanceof $e?void 0:e,a=new Ye(null!=n?n:await async function(){const{default:e}=await import("puppeteer"),t=await e.launch({headless:!0}),n=await t.newPage();return new je(t,n)}());return r&&(a.flow=r),a}Be=new WeakMap,De=new WeakMap,He=new WeakMap;class ze extends R{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${X(t,e.getIndent())});`)}}function Ge(e){var r;return Boolean(e.type===t.Navigate||(null===(r=e.assertedEvents)||void 0===r?void 0:r.some((e=>e.type===n.Navigation))))}function Qe(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ze extends me{constructor(){super(...arguments),Ke.set(this,!1)}async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${X({screenEmulation:{disabled:!0}},e.getIndent())}`),Qe(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${X(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const a=Ge(n);a?(B(this,Ke,"f")&&(e.appendLine("await lhFlow.endTimespan();"),D(this,Ke,!1,"f")),e.appendLine("await lhFlow.startNavigation();")):B(this,Ke,"f")||(e.appendLine("await lhFlow.startTimespan();"),D(this,Ke,!0,"f")),await super.stringifyStep(e,n,r),a&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){B(this,Ke,"f")&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}Ke=new WeakMap;class et extends Ve{constructor(){super(...arguments),Ue.set(this,!1),qe.set(this,!1),Xe.set(this,void 0)}async createFlowResult(){if(!B(this,Xe,"f"))throw new Error("Cannot get flow result before running the flow");return B(this,Xe,"f").createFlowResult()}async beforeAllSteps(e){var t;await(null===(t=super.beforeAllSteps)||void 0===t?void 0:t.call(this,e));const{startFlow:n,desktopConfig:r}=await import("lighthouse");let a;Qe(e)||(a=r),D(this,Xe,await n(this.page,{config:a,flags:{screenEmulation:{disabled:!0}},name:e.title}),"f")}async beforeEachStep(e,n){var r;await(null===(r=super.beforeEachStep)||void 0===r?void 0:r.call(this,e,n)),e.type!==t.SetViewport&&(Ge(e)?(B(this,Ue,"f")&&(await B(this,Xe,"f").endTimespan(),D(this,Ue,!1,"f")),await B(this,Xe,"f").startNavigation(),D(this,qe,!0,"f")):B(this,Ue,"f")||(await B(this,Xe,"f").startTimespan(),D(this,Ue,!0,"f")))}async afterEachStep(e,t){var n;B(this,qe,"f")&&(await B(this,Xe,"f").endNavigation(),D(this,qe,!1,"f")),await(null===(n=super.afterEachStep)||void 0===n?void 0:n.call(this,e,t))}async afterAllSteps(e){var t;B(this,Ue,"f")&&await B(this,Xe,"f").endTimespan(),await(null===(t=super.afterAllSteps)||void 0===t?void 0:t.call(this,e))}}Ue=new WeakMap,qe=new WeakMap,Xe=new WeakMap;export{n as AssertedEventType,M as JSONStringifyExtension,et as LighthouseRunnerExtension,Ze as LighthouseStringifyExtension,ze as PuppeteerReplayStringifyExtension,Ve as PuppeteerRunnerExtension,je as PuppeteerRunnerOwningBrowserExtension,me as PuppeteerStringifyExtension,Ye as Runner,$e as RunnerExtension,r as Schema,e as SelectorType,t as StepType,R as StringifyExtension,a as assertAllStepTypesAreHandled,_e as createRunner,z as formatAsJSLiteral,X as formatJSONAsJS,O as getSelectorType,V as maxTimeout,N as minTimeout,s as mouseButtonMap,W as parse,Ae as parseSourceMap,T as parseStep,o as pointerDeviceTypes,Le as stringify,ke as stringifyStep,Ce as stripSourceMap,i as typeableInputTypes,P as validTimeout};
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout};

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High library

This string may still contain
<!--
, which may cause an HTML element injection vulnerability.
@@ -1 +1 @@
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e=e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t=t||(t={})),function(e){e.Navigation="navigation"}(n=n||(n={}));var r=Object.freeze({__proto__:null,get SelectorType(){return e},get StepType(){return t},get AssertedEventType(){return n}});function a(e){throw new Error(`Unknown step type: ${e.type}`)}const i=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function l(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function c(e){return"object"==typeof e&&null!==e}function u(e){return"string"==typeof e}function p(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function w(e){if(l(e,"target")&&u(e.target))return e.target}function d(e){if(l(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(l(e,t)){const n=e[t];if(p(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(l(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function y(e,t){if(l(e,t))return h(e,t)}function g(e,t){if(l(e,t))return b(e,t)}function v(e,t){if(l(e,t))return m(e,t)}function b(e,t){if(l(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!l(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!u(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!u(e))throw new Error("Selector element is not a string");return e})):e}))}function S(e){if(l(e,"selectors"))return E(e)}function L(e){if(!c(e))throw new Error("Asserted event is not an object");if(!l(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:g(e,"url"),title:g(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(l(t,"timeout")&&p(t.timeout)&&!P(t.timeout))throw new Error(j);return{type:e,assertedEvents:l(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:l(t,"timeout")&&p(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:w(t)}}function C(e,t){return{...A(e,t),frame:d(t)}}function $(e,t){return{...C(e,t),selectors:E(t)}}function x(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:y(e,"duration")},n=g(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const a=g(e,"button");if(a){if(!function(e){return"string"==typeof e&&s.has(e)}(a))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=a}return t}function T(e,n){if(!c(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!l(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!u(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...$(t.Click,e),...x(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...$(t.DoubleClick,e),...x(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...$(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...$(t.Change,e),type:t.Change,value:b(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:b(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:b(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...C(t.Scroll,e),type:t.Scroll,x:y(e,"x"),y:y(e,"y"),selectors:S(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:w(e),url:b(e,"url")}}(e);case t.CustomStep:return function(e){if(!l(e,"name"))throw new Error("customStep is missing name");if(!u(e.name))throw new Error("customStep's name is not a string");return{...C(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:l(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=g(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(l(e,"attributes")&&(!c(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(l(e,"properties")&&!c(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...$(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:y(e,"count"),visible:v(e,"visible"),attributes:l(e,"attributes")?e.attributes:void 0,properties:l(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!l(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...C(t.WaitForExpression,e),type:t.WaitForExpression,expression:b(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function I(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push(T(r,n));return t}const N=1,V=3e4,j="Timeout is not between 1 and 30000 milliseconds";function P(e){return e>=1&&e<=3e4}function W(e){if(!c(e))throw new Error("Recording is not an object");if(!l(e,"title"))throw new Error("Recording is missing `title`");if(!u(e.title))throw new Error("Recording `title` is not a string");if(l(e,"timeout")&&!p(e.timeout))throw new Error("Recording `timeout` is not a number");if(!l(e,"steps"))throw new Error("Recording is missing `steps`");if(l(e,"timeout")&&p(e.timeout)&&!P(e.timeout))throw new Error(j);return t={title:e.title,timeout:l(e,"timeout")&&p(e.timeout)?e.timeout:void 0,selectorAttribute:l(e,"selectorAttribute")&&u(e.selectorAttribute)?e.selectorAttribute:void 0,steps:I(e.steps)},JSON.parse(JSON.stringify(t));var t}function O(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}class R{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class M extends R{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const a=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+a)}}function B(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function D(e,t,n,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?a.call(e,n):a?a.value=n:t.set(e,n),n}var H,K,U;class q{constructor(e){H.set(this,void 0),K.set(this,0),U.set(this,[]),D(this,H,e,"f")}appendLine(e){const t=e.split("\n").map((e=>e?B(this,H,"f").repeat(B(this,K,"f"))+e.trimEnd():""));return B(this,U,"f").push(...t),this}startBlock(){var e;return D(this,K,(e=B(this,K,"f"),++e),"f"),this}endBlock(){var e;return D(this,K,(e=B(this,K,"f"),--e),"f"),this}toString(){return B(this,U,"f").join("\n")+"\n"}getIndent(){return B(this,H,"f")}getSize(){return B(this,U,"f").length}}function X(e,t){const n=[];return J(e,n,1,t),n.join("")}function J(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(z(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let a=0;a<e.length;a++)t.push(r.repeat(n)),J(e[a],t,n+1,r),a!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const a=Object.keys(e);for(let i=0;i<a.length;i++){const o=a[i],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),J(s,t,n+1,r),i!==a.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}H=new WeakMap,K=new WeakMap,U=new WeakMap;const Y=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),_=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),z=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(_.has(n))return _.get(n);return"\\x"+Y(n.charCodeAt(0),2)}if(r){return"\\u"+Y(r.charCodeAt(0),4)}return t?_.get(t)||"":e};let a="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",a=e.replace(n,r)):(i="`",a=e.replace(t,r)):(i='"',a=e.replace(t,r)):(i="'",a=e.replace(t,r)),`${i}${a}${i}`};var G,Q,Z,ee,te,ne,re,ae,ie,oe,se,le,ce,ue,pe,fe,we,de,he;class me extends R{constructor(){super(...arguments),G.add(this)}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v13.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||ye};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine("")}async afterAllSteps(e,t){e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine("");for(const t of ge.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),B(this,G,"m",ee).call(this,e,t),t.assertedEvents){e.appendLine("const promises = [];");for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}}B(this,G,"m",fe).call(this,e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}}G=new WeakSet,Q=function(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${X(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))},Z=function(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)},ee=function(e,t){B(this,G,"m",Q).call(this,e,t.target||"main"),t.frame&&B(this,G,"m",Z).call(this,e,t.frame)},te=function(e,t){e.appendLine(`await scrollIntoViewIfNeeded(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`),e.appendLine(`const element = await waitForSelectors(${X(t.selectors,e.getIndent())}, ${t.frame?"frame":"targetPage"}, { timeout, visible: true });`)},ne=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},re=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.click({"),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});"),e.appendLine("await element.click({"),e.appendLine(" clickCount: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")},ae=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("await element.hover();")},ie=function(e,t){B(this,G,"m",te).call(this,e,t),e.appendLine("const inputType = await element.evaluate(el => el.type);"),e.appendLine("if (inputType === 'select-one') {"),e.appendLine(` await changeSelectElement(element, ${X(t.value,e.getIndent())})`),e.appendLine(`} else if (${X(Array.from(i),e.getIndent())}.includes(inputType)) {`),e.appendLine(` await typeIntoElement(element, ${X(t.value,e.getIndent())});`),e.appendLine("} else {"),e.appendLine(` await changeElementValue(element, ${X(t.value,e.getIndent())});`),e.appendLine("}")},oe=function(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")},se=function(e,t){e.appendLine(`await targetPage.keyboard.down(${X(t.key,e.getIndent())});`)},le=function(e,t){e.appendLine(`await targetPage.keyboard.up(${X(t.key,e.getIndent())});`)},ce=function(e,t){e.appendLine("await targetPage.close()")},ue=function(e,t){e.appendLine(`await targetPage.setViewport(${X({width:t.width,height:t.height},e.getIndent())})`)},pe=function(e,t){"selectors"in t?(B(this,G,"m",te).call(this,e,t),e.appendLine(`await element.evaluate((el, x, y) => { el.scrollTop = y; el.scrollLeft = x; }, ${t.x}, ${t.y});`)):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)},fe=function(e,n){switch(n.type){case t.Click:return B(this,G,"m",ne).call(this,e,n);case t.DoubleClick:return B(this,G,"m",re).call(this,e,n);case t.Hover:return B(this,G,"m",ae).call(this,e,n);case t.Change:return B(this,G,"m",ie).call(this,e,n);case t.EmulateNetworkConditions:return B(this,G,"m",oe).call(this,e,n);case t.KeyDown:return B(this,G,"m",se).call(this,e,n);case t.KeyUp:return B(this,G,"m",le).call(this,e,n);case t.Close:return B(this,G,"m",ce).call(this,e,n);case t.SetViewport:return B(this,G,"m",ue).call(this,e,n);case t.Scroll:return B(this,G,"m",pe).call(this,e,n);case t.Navigate:return B(this,G,"m",we).call(this,e,n);case t.WaitForElement:return B(this,G,"m",he).call(this,e,n);case t.WaitForExpression:return B(this,G,"m",de).call(this,e,n);case t.CustomStep:return;default:return a(n)}},we=function(e,t){e.appendLine(`await targetPage.goto(${X(t.url,e.getIndent())});`)},de=function(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${X(t.expression,e.getIndent())}, { timeout });`)},he=function(e,t){e.appendLine(`await waitForElement(${X(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)};const ye=5e3,ge="async function waitForSelectors(selectors, frame, options) {\n for (const selector of selectors) {\n try {\n return await waitForSelector(selector, frame, options);\n } catch (err) {\n console.error(err);\n }\n }\n throw new Error('Could not find element for selectors: ' + JSON.stringify(selectors));\n}\n\nasync function scrollIntoViewIfNeeded(selectors, frame, timeout) {\n const element = await waitForSelectors(selectors, frame, { visible: false, timeout });\n if (!element) {\n throw new Error(\n 'The element could not be found.'\n );\n }\n await waitForConnected(element, timeout);\n const isInViewport = await element.isIntersectingViewport({threshold: 0});\n if (isInViewport) {\n return;\n }\n await element.evaluate(element => {\n element.scrollIntoView({\n block: 'center',\n inline: 'center',\n behavior: 'auto',\n });\n });\n await waitForInViewport(element, timeout);\n}\n\nasync function waitForConnected(element, timeout) {\n await waitForFunction(async () => {\n return await element.getProperty('isConnected');\n }, timeout);\n}\n\nasync function waitForInViewport(element, timeout) {\n await waitForFunction(async () => {\n return await element.isIntersectingViewport({threshold: 0});\n }, timeout);\n}\n\nasync function waitForSelector(selector, frame, options) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to waitForSelector');\n }\n let element = null;\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (element) {\n element = await element.waitForSelector(part, options);\n } else {\n element = await frame.waitForSelector(part, options);\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('>>'));\n }\n if (i < selector.length - 1) {\n element = (await element.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n }\n }\n if (!element) {\n throw new Error('Could not find element: ' + selector.join('|'));\n }\n return element;\n}\n\nasync function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}\n\nasync function changeSelectElement(element, value) {\n await element.select(value);\n await element.evaluateHandle((e) => {\n e.blur();\n e.focus();\n });\n}\n\nasync function changeElementValue(element, value) {\n await element.focus();\n await element.evaluate((input, value) => {\n input.value = value;\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n }, value);\n}\n\nasync function typeIntoElement(element, value) {\n const textToType = await element.evaluate((input, newValue) => {\n if (\n newValue.length <= input.value.length ||\n !newValue.startsWith(input.value)\n ) {\n input.value = '';\n return newValue;\n }\n const originalValue = input.value;\n input.value = '';\n input.value = originalValue;\n return newValue.substring(originalValue.length);\n }, value);\n await element.type(textToType);\n}",ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",be=ve.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map);function Ee(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>2147483647)throw new Error("Only integers between 0 and 2147483647 are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(ve[n])}while(0!==e);return t.join("")}function Se(e){const t=[],n=e.split("");let r=0,a=0;for(const e of n){const n=be.get(e);r|=(31&n)<<a,a+=5;32&n||(t.push(r),r=0,a=0)}return t}async function Le(e,t){var n,r,a,i,o,s,l;t||(t={});const c=null!==(n=t.extension)&&void 0!==n?n:new me,u=null!==(r=t.writer)&&void 0!==r?r:new q(null!==(a=t.indentation)&&void 0!==a?a:" ");await(null===(i=c.beforeAllSteps)||void 0===i?void 0:i.call(c,u,e));const p=[1];for(const t of e.steps){const n=u.getSize();await(null===(o=c.beforeEachStep)||void 0===o?void 0:o.call(c,u,t,e)),await c.stringifyStep(u,t,e),await(null===(s=c.afterEachStep)||void 0===s?void 0:s.call(c,u,t,e));const r=u.getSize();p.push(n,r-n)}return await(null===(l=c.afterAllSteps)||void 0===l?void 0:l.call(c,u,e)),u.appendLine("//# recorderSourceMap="+function(e){const t=[];for(const n of e)t.push(Ee(n));return t.join("")}(p)),u.toString()}async function ke(e,t){var n,r,a,i;t||(t={});let o=t.extension;o||(o=new me),t.indentation||(t.indentation=" ");const s=null!==(n=t.writer)&&void 0!==n?n:new q(null!==(r=t.indentation)&&void 0!==r?r:" ");return await(null===(a=o.beforeEachStep)||void 0===a?void 0:a.call(o,s,e)),await o.stringifyStep(s,e),await(null===(i=o.afterEachStep)||void 0===i?void 0:i.call(o,s,e)),s.toString()}function Fe(e){return e.trim().startsWith("//# recorderSourceMap=")}function Ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(Fe(n))return Se(n.trim().substring("//# recorderSourceMap=".length))}}function Ce(e){return e.split("\n").filter((e=>!Fe(e))).join("\n")}class $e{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}var xe,Te,Ie;const Ne={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};class Ve extends $e{constructor(e,t,n){super(),xe.add(this),this.browser=e,this.page=t,this.timeout=(null==n?void 0:n.timeout)||5e3}async runStep(e,t){const n=B(this,xe,"m",Ie).call(this,e,t),r=this.page,a=this.browser,i=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const a=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),i=await a.page();if(!i)return null;return i.setDefaultTimeout(r),i}(a,r,e,n);let o=null;if(!i&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||i;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await B(this,xe,"m",Te).call(this,s);const l=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,l,n)}async runStepInFrame(e,r,o,l,c){const u=!0;let p=null;const f=()=>{p=async function(e,t,r){const a=[];if(t.assertedEvents)for(const i of t.assertedEvents){if(i.type!==n.Navigation)throw new Error(`Event type ${i.type} is not supported`);a.push(e.waitForNavigation({timeout:r}))}await Promise.all(a)}(l,e,c)};switch(e.type){case t.DoubleClick:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.click({clickCount:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Click:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}}),await t.dispose()}break;case t.Hover:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);f(),await t.hover(),await t.dispose()}break;case t.EmulateNetworkConditions:f(),await r.emulateNetworkConditions(e);break;case t.KeyDown:f(),await r.keyboard.down(e.key),await r.waitForTimeout(100);break;case t.KeyUp:f(),await r.keyboard.up(e.key),await r.waitForTimeout(100);break;case t.Close:"close"in o&&(f(),await o.close());break;case t.Change:{await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});if(!t)throw new Error("Could not find element: "+e.selectors[0]);const n=await t.evaluate((e=>e.type));f(),"select-one"===n?await this.changeSelectElement(e,t):i.has(n)?await this.typeIntoElement(e,t):await this.changeElementValue(e,t),await t.dispose()}break;case t.SetViewport:"setViewport"in o&&(f(),await o.setViewport(e));break;case t.Scroll:if("selectors"in e){await Pe(e.selectors,l,c);const t=await We(e.selectors,l,{timeout:c,visible:u});f(),await t.evaluate(((e,t,n)=>{e.scrollTop=n,e.scrollLeft=t}),e.x||0,e.y||0),await t.dispose()}else f(),await l.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0);break;case t.Navigate:f(),await l.goto(e.url);break;case t.WaitForElement:try{f(),await async function(e,t,n){const{count:r=1,operator:a=">=",visible:i=!0,properties:o,attributes:s}=e,l=Ne[a];await Me((async()=>{const n=await async function(e,t){for(const n of e){const e=await Re(n,t);if(e.length)return e}return[]}(e.selectors,t);let a=l(n.length,r);const c=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),a&&(o||s)&&(a=await c.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,a]of Object.entries(e))if(!r(a,t[n]))return!1;return!0}}),o,s)),await c.dispose(),a===i}),n)}(e,l,c)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:f(),await l.waitForFunction(e.expression,{timeout:c});break;case t.CustomStep:break;default:a(e)}await p}async typeIntoElement(e,t){const n=await t.evaluate(((e,t)=>{if(t.length<=e.value.length||!t.startsWith(e.value))return e.value="",t;const n=e.value;return e.value="",e.value=n,t.substring(n.length)}),e.value);await t.type(n)}async changeElementValue(e,t){await t.focus(),await t.evaluate(((e,t)=>{e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}),e.value)}async changeSelectElement(e,t){await t.select(e.value),await t.evaluateHandle((e=>{e.blur(),e.focus()}))}}xe=new WeakSet,Te=async function(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}},Ie=function(e,t){return e.timeout||(null==t?void 0:t.timeout)||this.timeout};class je extends Ve{async afterAllSteps(){await this.browser.close()}}async function Pe(e,t,n){const r=await We(e,t,{visible:!1,timeout:n});if(!r)throw new Error("The element could not be found.");await async function(e,t){await Me((async()=>await e.evaluate((e=>e.isConnected))),t)}(r,n);const a=await(async e=>await e.evaluate((e=>e instanceof SVGElement))?e:null)(r),i=a?await async function(e){return await e.evaluateHandle((e=>{var t;return null!==(t=e.ownerSVGElement)&&void 0!==t?t:e}))}(a):r;!!i&&await i.isIntersectingViewport({threshold:0})||(await async function(e){await e.evaluate((e=>{e.scrollIntoView({block:"center",inline:"center",behavior:"auto"})}))}(r),i&&await async function(e,t){await Me((async()=>await e.isIntersectingViewport({threshold:0})),t)}(i,n),await i.dispose(),i!==r&&await r.dispose())}async function We(e,t,n){for(const r of e)try{return await Oe(r,t,n)}catch(e){console.error("error in waitForSelectors",e)}throw new Error("Could not find element for selectors: "+JSON.stringify(e))}async function Oe(e,t,n){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to `waitForSelector`");let r=1===e.length,a=await t.waitForSelector(e[0],{...n,visible:r&&n.visible});for(const t of e.slice(1,e.length)){if(!a)throw new Error("Could not find element: "+e.join(">>"));const i=await a.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e));a.dispose(),r=e[e.length-1]===t,a=await i.waitForSelector(t,{...n,visible:r&&n.visible}),i.dispose()}if(!a)throw new Error("Could not find element: "+e.join(">>"));return a}async function Re(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function Me(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}var Be,De,He,Ke,Ue,qe,Xe;async function Je(e,t,n){var r,a;await(null===(r=e.beforeEachStep)||void 0===r?void 0:r.call(e,t,n)),await e.runStep(t,n),await(null===(a=e.afterEachStep)||void 0===a?void 0:a.call(e,t,n))}class Ye{constructor(e){Be.set(this,void 0),De.set(this,void 0),He.set(this,!1),D(this,De,e,"f")}abort(){D(this,He,!0,"f")}set flow(e){D(this,Be,e,"f")}async runBeforeAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).beforeAllSteps)||void 0===n?void 0:n.call(t,e))}async runAfterAllSteps(e){var t,n;await(null===(n=(t=B(this,De,"f")).afterAllSteps)||void 0===n?void 0:n.call(t,e))}async runStep(e){await Je(B(this,De,"f"),e)}async run(){var e,t,n,r,a,i;if(!B(this,Be,"f"))throw new Error("Set the flow on the runner instance before calling `run`.");const o=B(this,Be,"f");if(D(this,He,!1,"f"),await(null===(t=(e=B(this,De,"f")).beforeAllSteps)||void 0===t?void 0:t.call(e,o)),B(this,He,"f"))return!1;for(const e of o.steps){if(B(this,He,"f"))return await(null===(r=(n=B(this,De,"f")).afterAllSteps)||void 0===r?void 0:r.call(n,o)),!1;await Je(B(this,De,"f"),e,o)}return await(null===(i=(a=B(this,De,"f")).afterAllSteps)||void 0===i?void 0:i.call(a,o)),!0}}async function _e(e,t){const n=e instanceof $e?e:t,r=e instanceof $e?void 0:e,a=new Ye(null!=n?n:await async function(){const{default:e}=await import("puppeteer"),t=await e.launch({headless:!0}),n=await t.newPage();return new je(t,n)}());return r&&(a.flow=r),a}Be=new WeakMap,De=new WeakMap,He=new WeakMap;class ze extends R{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${X(t,e.getIndent())});`)}}function Ge(e){var r;return Boolean(e.type===t.Navigate||(null===(r=e.assertedEvents)||void 0===r?void 0:r.some((e=>e.type===n.Navigation))))}function Qe(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ze extends me{constructor(){super(...arguments),Ke.set(this,!1)}async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${X({screenEmulation:{disabled:!0}},e.getIndent())}`),Qe(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${X(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const a=Ge(n);a?(B(this,Ke,"f")&&(e.appendLine("await lhFlow.endTimespan();"),D(this,Ke,!1,"f")),e.appendLine("await lhFlow.startNavigation();")):B(this,Ke,"f")||(e.appendLine("await lhFlow.startTimespan();"),D(this,Ke,!0,"f")),await super.stringifyStep(e,n,r),a&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){B(this,Ke,"f")&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}Ke=new WeakMap;class et extends Ve{constructor(){super(...arguments),Ue.set(this,!1),qe.set(this,!1),Xe.set(this,void 0)}async createFlowResult(){if(!B(this,Xe,"f"))throw new Error("Cannot get flow result before running the flow");return B(this,Xe,"f").createFlowResult()}async beforeAllSteps(e){var t;await(null===(t=super.beforeAllSteps)||void 0===t?void 0:t.call(this,e));const{startFlow:n,desktopConfig:r}=await import("lighthouse");let a;Qe(e)||(a=r),D(this,Xe,await n(this.page,{config:a,flags:{screenEmulation:{disabled:!0}},name:e.title}),"f")}async beforeEachStep(e,n){var r;await(null===(r=super.beforeEachStep)||void 0===r?void 0:r.call(this,e,n)),e.type!==t.SetViewport&&(Ge(e)?(B(this,Ue,"f")&&(await B(this,Xe,"f").endTimespan(),D(this,Ue,!1,"f")),await B(this,Xe,"f").startNavigation(),D(this,qe,!0,"f")):B(this,Ue,"f")||(await B(this,Xe,"f").startTimespan(),D(this,Ue,!0,"f")))}async afterEachStep(e,t){var n;B(this,qe,"f")&&(await B(this,Xe,"f").endNavigation(),D(this,qe,!1,"f")),await(null===(n=super.afterEachStep)||void 0===n?void 0:n.call(this,e,t))}async afterAllSteps(e){var t;B(this,Ue,"f")&&await B(this,Xe,"f").endTimespan(),await(null===(t=super.afterAllSteps)||void 0===t?void 0:t.call(this,e))}}Ue=new WeakMap,qe=new WeakMap,Xe=new WeakMap;export{n as AssertedEventType,M as JSONStringifyExtension,et as LighthouseRunnerExtension,Ze as LighthouseStringifyExtension,ze as PuppeteerReplayStringifyExtension,Ve as PuppeteerRunnerExtension,je as PuppeteerRunnerOwningBrowserExtension,me as PuppeteerStringifyExtension,Ye as Runner,$e as RunnerExtension,r as Schema,e as SelectorType,t as StepType,R as StringifyExtension,a as assertAllStepTypesAreHandled,_e as createRunner,z as formatAsJSLiteral,X as formatJSONAsJS,O as getSelectorType,V as maxTimeout,N as minTimeout,s as mouseButtonMap,W as parse,Ae as parseSourceMap,T as parseStep,o as pointerDeviceTypes,Le as stringify,ke as stringifyStep,Ce as stripSourceMap,i as typeableInputTypes,P as validTimeout};
var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout};

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High library

This string may still contain
<!--
, which may cause an HTML element injection vulnerability.
<${s.Icon.Icon.litTagName} .data=${{iconPath:e,color:t,width:o,height:r}}></${s.Icon.Icon.litTagName}>
`}#g(){if(!this.#h)return i.html``;const{src:e,width:t="100%",height:o="100%"}=this.#h;return i.html`
<img class="markdown-image" src=${e} alt=${this.#p} width=${t} height=${o}/>
`}#d(){if(!this.#h)return;const{isIcon:e}=this.#h,t=e?this.#m():this.#g();i.render(t,this.#e,{host:this})}}customElements.define("devtools-markdown-image",k);var x=Object.freeze({__proto__:null,MarkdownImage:k});const v=new CSSStyleSheet;v.replaceSync(".devtools-link{color:var(--sys-color-primary);outline-offset:2px;text-decoration:none}.devtools-link:hover{text-decoration:underline}\n/*# sourceURL=markdownLink.css */\n");const y=new Map([["issuesContrastWCAG21AA","https://www.w3.org/TR/WCAG21/#contrast-minimum"],["issuesContrastWCAG21AAA","https://www.w3.org/TR/WCAG21/#contrast-enhanced"],["issuesContrastSuggestColor","https://developers.google.com/web/updates/2020/08/devtools#accessible-color"],["issuesCSPSetStrict","https://web.dev/strict-csp"],["issuesCSPWhyStrictOverAllowlist","https://web.dev/strict-csp/#why-a-strict-csp-is-recommended-over-allowlist-csps"],["issueCorsPreflightRequest","https://web.dev/cross-origin-resource-sharing/#preflight-requests-for-complex-http-calls"],["issueQuirksModeDoctype","https://web.dev/doctype/"],["sameSiteAndSameOrigin","https://web.dev/same-site-same-origin/"],["punycodeReference","https://wikipedia.org/wiki/Punycode"],["https://xhr.spec.whatwg.org/","https://xhr.spec.whatwg.org/"],["https://goo.gle/chrome-insecure-origins","https://goo.gle/chrome-insecure-origins"],["https://webrtc.org/web-apis/chrome/unified-plan/","https://webrtc.org/web-apis/chrome/unified-plan/"],["https://developer.chrome.com/blog/enabling-shared-array-buffer/","https://developer.chrome.com/blog/enabling-shared-array-buffer/"],["https://developer.chrome.com/docs/extensions/mv3/","https://developer.chrome.com/docs/extensions/mv3/"],["https://developer.chrome.com/blog/immutable-document-domain/","https://developer.chrome.com/blog/immutable-document-domain/"],["https://github.com/WICG/shared-element-transitions/blob/main/debugging_overflow_on_images.md","https://github.com/WICG/shared-element-transitions/blob/main/debugging_overflow_on_images.md"],["https://developer.chrome.com/docs/extensions/reference/privacy/#property-websites-privacySandboxEnabled","https://developer.chrome.com/docs/extensions/reference/privacy/#property-websites-privacySandboxEnabled"],["PNASecureContextRestrictionFeatureStatus","https://chromestatus.com/feature/5954091755241472"],["https://w3c.github.io/uievents/#legacy-event-types","https://w3c.github.io/uievents/#legacy-event-types"],["https://support.google.com/chrome/answer/95647","https://support.google.com/chrome/answer/95647"]]),b=e=>{if(/^https:\/\/www.chromestatus.com\/feature\/\d+$/.test(e))return e;const t=y.get(e);if(!t)throw new Error(`Markdown link with key '${e}' is not available, please check MarkdownLinksMap.ts`);return t};var f=Object.freeze({__proto__:null,markdownLinks:y,getMarkdownLink:b});class T extends HTMLElement{static litTagName=i.literal`devtools-markdown-link`;#e=this.attachShadow({mode:"open"});#u="";#w="";connectedCallback(){this.#e.adoptedStyleSheets=[v]}set data(e){const{key:t,title:o}=e,r=b(t);this.#u=o,this.#w=r,this.#d()}#d(){const e=i.html`

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High library

This regular expression has an unescaped '.' before 'chromestatus.com', so it might match more hosts than expected.
@@ -0,0 +1,28 @@
import*as e from"../code_highlighter/code_highlighter.js";import*as t from"../../lit-html/lit-html.js";import*as o from"../../visual_logging/visual_logging.js";const s=new CSSStyleSheet;s.replaceSync(".token-variable{color:var(--sys-color-token-variable)}.token-property{color:var(--sys-color-token-property)}.token-type{color:var(--sys-color-token-type)}.token-variable-special{color:var(--sys-color-token-variable-special)}.token-definition{color:var(--sys-color-token-definition)}.token-builtin{color:var(--sys-color-token-builtin)}.token-number{color:var(--sys-color-token-number)}.token-string{color:var(--sys-color-token-string)}.token-string-special{color:var(--sys-color-token-string-special)}.token-atom{color:var(--sys-color-token-atom)}.token-keyword{color:var(--sys-color-token-keyword)}.token-comment{color:var(--sys-color-token-comment)}.token-meta{color:var(--sys-color-token-meta)}.token-invalid{color:var(--sys-color-error)}.token-tag{color:var(--sys-color-token-tag)}.token-attribute{color:var(--sys-color-token-attribute)}.token-attribute-value{color:var(--sys-color-token-attribute-value)}.token-inserted{color:var(--sys-color-token-inserted)}.token-deleted{color:var(--sys-color-token-deleted)}.token-heading{color:var(--sys-color-token-variable-special);font-weight:bold}.token-link{color:var(--sys-color-token-variable-special);text-decoration:underline}.token-strikethrough{text-decoration:strike-through}.token-strong{font-weight:bold}.token-emphasis{font-style:italic}\n/*# sourceURL=codeHighlighter.css */\n");const i=new CSSStyleSheet;i.replaceSync('*{box-sizing:border-box;font-size:inherit;margin:0;padding:0}:host{position:relative}devtools-editable-content{background:transparent;border:none;color:var(--override-color-recorder-input,var(--sys-color-on-surface));cursor:text;display:inline-block;line-height:18px;min-height:18px;min-width:0.5em;outline:none;overflow-wrap:anywhere}devtools-editable-content:hover,\ndevtools-editable-content:focus{box-shadow:0 0 0 1px var(--sys-color-divider);border-radius:2px}devtools-editable-content[placeholder]:empty::before{content:attr(placeholder);color:var(--sys-color-on-surface);opacity:50%}devtools-editable-content[placeholder]:empty:focus::before{content:""}devtools-suggestion-box{position:absolute;display:none}devtools-editable-content:focus ~ devtools-suggestion-box{display:block}.suggestions{background-color:var(--sys-color-cdt-base-container);box-shadow:var(--drop-shadow);min-height:1em;min-width:150px;overflow-x:hidden;overflow-y:auto;position:relative;z-index:100;max-height:350px}.suggestions > li{padding:1px;border:1px solid transparent;white-space:nowrap;font-family:var(--source-code-font-family);font-size:var(--source-code-font-size);color:var(--sys-color-on-surface)}.suggestions > li:hover{background-color:var(--sys-color-state-hover-on-subtle)}.suggestions > li.selected{background-color:var(--sys-color-primary);color:var(--sys-color-cdt-base-container)}.strikethrough{text-decoration:line-through}\n/*# sourceURL=suggestionInput.css */\n');var n=self&&self.__decorate||function(e,t,o,s){var i,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,o,s);else for(var l=e.length-1;l>=0;l--)(i=e[l])&&(r=(n<3?i(r):n>3?i(t,o,r):i(t,o))||r);return n>3&&r&&Object.defineProperty(t,o,r),r};function r(e,t="Assertion failed!"){if(!e)throw new Error(t)}const{html:l,Decorators:a,Directives:c,LitElement:h}=t,{customElement:d,property:u,state:g}=a,{classMap:p}=c,v={hasChanged:(e,t)=>JSON.stringify(e)!==JSON.stringify(t)};let y=class extends HTMLElement{static get observedAttributes(){return["disabled","placeholder"]}set disabled(e){this.contentEditable=String(!e)}get disabled(){return"true"!==this.contentEditable}set value(e){this.innerText=e,this.#e()}get value(){return this.innerText}set mimeType(e){this.#t=e,this.#e()}get mimeType(){return this.#t}#t="";constructor(){super(),this.contentEditable="true",this.tabIndex=0,this.addEventListener("focus",(()=>{this.innerHTML=this.innerText})),this.addEventListener("blur",this.#e.bind(this))}#e(){this.#t&&e.CodeHighlighter.highlightNode(this,this.#t)}attributeChangedCallback(e,t,o){if("disabled"===e)this.disabled=null!==o}};y=n([d("devtools-editable-content")],y);class b extends Event{static eventName="suggest";constructor(e){super(b.eventName),this.suggestion=e}}class m extends Event{static eventName="suggestioninit";listeners;constructor(e){super(m.eventName),this.listeners=e}}const k=(e,t)=>e.toLowerCase().startsWith(t.toLowerCase());let f=class extends h{static styles=[i];#o=[];constructor(){super(),this.options=[],this.expression="",this.cursor=0}#s=e=>{if(r(e instanceof KeyboardEvent,"Bound to the wrong event."),this.#o.length>0)switch(e.key){case"ArrowDown":e.stopPropagation(),e.preventDefault(),this.#i(1);break;case"ArrowUp":e.stopPropagation(),e.preventDefault(),this.#i(-1)}if("Enter"===e.key)this.#o[this.cursor]&&this.#n(this.#o[this.cursor]),e.preventDefault()};#i(e){var t,o;this.cursor=(t=this.cursor+e,o=this.#o.length,(t%o+o)%o)}#n(e){this.dispatchEvent(new b(e))}connectedCallback(){super.connectedCallback(),this.dispatchEvent(new m([["keydown",this.#s]]))}willUpdate(e){e.has("options")&&(this.options=Object.freeze([...this.options].sort())),(e.has("expression")||e.has("options"))&&(this.cursor=0,this.#o=this.options.filter((e=>(this.suggestionFilter||k)(e,this.expression))))}render(){if(0!==this.#o.length)return l`<ul class="suggestions">

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium library

DOM text
is reinterpreted as HTML without escaping meta-characters.
@@ -1 +1 @@
import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/host/host.js";import*as n from"../../../../core/i18n/i18n.js";import*as i from"../../../../core/platform/platform.js";import*as o from"../../../../core/sdk/sdk.js";import*as r from"../../../../models/bindings/bindings.js";import*as a from"../../legacy.js";import*as s from"../../../../models/breakpoints/breakpoints.js";import*as c from"../../../../models/text_utils/text_utils.js";import*as l from"../../../../models/workspace/workspace.js";const d=new CSSStyleSheet;d.replaceSync(".image-preview-container{background:transparent;text-align:center;border-spacing:0}.image-preview-container img{margin:6px 0;max-width:100px;max-height:100px;background-image:var(--image-file-checker);user-select:text;vertical-align:top;-webkit-user-drag:auto}.image-container{padding:0}.image-container > div{min-height:50px;display:flex;align-items:center;justify-content:center;cursor:pointer}.image-preview-container .row{line-height:1.2;vertical-align:baseline}.image-preview-container .title{padding-right:0.5em;text-align:right;color:var(--color-text-secondary);white-space:nowrap}.image-preview-container .description{white-space:nowrap;text-align:left;color:var(--color-text-primary)}.image-preview-container .description-link{max-width:20em}.image-preview-container .source-link{white-space:normal;word-break:break-all;color:var(--color-link);cursor:pointer}\n/*# sourceURL=imagePreview.css */\n");const u={unknownSource:"unknown source",imageFromS:"Image from {PH1}",fileSize:"File size:",intrinsicSize:"Intrinsic size:",renderedSize:"Rendered size:",currentSource:"Current source:",renderedAspectRatio:"Rendered aspect ratio:",intrinsicAspectRatio:"Intrinsic aspect ratio:"},p=n.i18n.registerUIStrings("ui/legacy/components/utils/ImagePreview.ts",u),g=n.i18n.getLocalizedString.bind(void 0,p);function m(t){return null!==t&&t.resourceType()===e.ResourceType.resourceTypes.Image}var h=Object.freeze({__proto__:null,ImagePreview:class{static async build(e,n,r,a={precomputedFeatures:void 0,imageAltText:void 0}){const{precomputedFeatures:s,imageAltText:c}=a,l=e.model(o.ResourceTreeModel.ResourceTreeModel);if(!l)return null;let p=l.resourceForURL(n),h=n;if(!m(p)&&s&&s.currentSrc&&(h=s.currentSrc,p=l.resourceForURL(h)),!p||!m(p))return null;const k=p,L=p.displayName,f=p.content?p.content:p.url.split("base64,")[1],b=p.contentSize(),C=b||i.StringUtilities.base64ToSize(f),w=C>0?i.NumberUtilities.bytesToString(C):"";return new Promise((e=>{const n=document.createElement("img");n.addEventListener("load",(function(){const o=document.createElement("div"),a=o.attachShadow({mode:"open"});a.adoptedStyleSheets=[d];const c=a.createChild("table");c.className="image-preview-container";const l=c.createChild("tr").createChild("td","image-container");l.colSpan=2;const p=l.createChild("div");p.title=L,p.appendChild(n),p.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(h)}));const m=n.naturalWidth,k=n.naturalHeight,f=s?s.renderedWidth:m,b=s?s.renderedHeight:k;if(r){const e=c.createChild("tr","row");e.createChild("td","title").textContent=g(u.renderedSize),e.createChild("td","description").textContent=`${f} × ${b} px`;const t=c.createChild("tr","row");if(t.createChild("td","title").textContent=g(u.renderedAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(f,b),b!==k||f!==m){const e=c.createChild("tr","row");e.createChild("td","title").textContent=g(u.intrinsicSize),e.createChild("td","description").textContent=`${m} × ${k} px`;const t=c.createChild("tr","row");t.createChild("td","title").textContent=g(u.intrinsicAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(m,k)}}const C=c.createChild("tr","row");C.createChild("td","title").textContent=g(u.fileSize),C.createChild("td","description").textContent=w;const v=c.createChild("tr","row");v.createChild("td","title").textContent=g(u.currentSource);const S=i.StringUtilities.trimMiddle(h,100),I=v.createChild("td","description description-link").createChild("span","source-link");I.textContent=S,I.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(h)})),e(o)}),!1),n.addEventListener("error",(()=>e(null)),!1),c&&(n.alt=c),k.populateImageSource(n)}))}static async loadDimensionsForNode(e){if(!e.nodeName()||"img"!==e.nodeName().toLowerCase())return;const t=await e.resolveToObject("");if(!t)return;const n=await t.callFunctionJSON((function(){return{renderedWidth:this.width,renderedHeight:this.height,currentSrc:this.currentSrc}}),void 0);return t.release(),n}static defaultAltTextForImageURL(t){const n=new e.ParsedURL.ParsedURL(t),i=n.isValid?n.displayName:g(u.unknownSource);return g(u.imageFromS,{PH1:i})}}});const k={unknown:"(unknown)",auto:"auto",revealInS:"Reveal in {PH1}",reveal:"Reveal",openUsingS:"Open using {PH1}",linkHandling:"Link handling:"},L=n.i18n.registerUIStrings("ui/legacy/components/utils/Linkifier.ts",k),f=n.i18n.getLocalizedString.bind(void 0,L),b=new Set;let C=null;const w=new WeakMap,v=new WeakMap,S=new WeakMap,I=new Map;let y;class x{maxLength;anchorsByTarget;locationPoolByTarget;onLiveLocationUpdate;useLinkDecorator;constructor(e,t,n=(()=>{})){this.maxLength=e||a.UIUtils.MaxLengthForDisplayedURLs,this.anchorsByTarget=new Map,this.locationPoolByTarget=new Map,this.onLiveLocationUpdate=n,this.useLinkDecorator=Boolean(t),b.add(this),o.TargetManager.TargetManager.instance().observeTargets(this)}static setLinkDecorator(e){console.assert(!C,"Cannot re-register link decorator."),C=e,e.addEventListener(T.Events.LinkIconChanged,(function(e){const t=e.data,n=w.get(t)||[];for(const e of n)x.updateLinkDecorations(e)}));for(const e of b)e.updateAllAnchorDecorations()}updateAllAnchorDecorations(){for(const e of this.anchorsByTarget.values())for(const t of e)x.updateLinkDecorations(t)}static bindUILocation(e,t){const n=x.linkInfo(e);if(!n)return;if(n.uiLocation=t,!t)return;const i=t.uiSourceCode;let o=w.get(i);o||(o=new Set,w.set(i,o)),o.add(e)}static unbindUILocation(e){const t=x.linkInfo(e);if(!t||!t.uiLocation)return;const n=t.uiLocation.uiSourceCode;t.uiLocation=null;const i=w.get(n);i&&i.delete(e)}static bindBreakpoint(e,t){const n=x.linkInfo(e);if(!n)return;const i=s.BreakpointManager.BreakpointManager.instance().findBreakpoint(t);i&&(n.revealable=i)}static unbindBreakpoint(e){const t=x.linkInfo(e);t&&t.revealable&&(t.revealable=null)}targetAdded(e){this.anchorsByTarget.set(e,[]),this.locationPoolByTarget.set(e,new r.LiveLocation.LiveLocationPool)}targetRemoved(e){const t=this.locationPoolByTarget.get(e);if(this.locationPoolByTarget.delete(e),!t)return;t.disposeAll();const n=this.anchorsByTarget.get(e);if(n){this.anchorsByTarget.delete(e);for(const e of n){const t=x.linkInfo(e);if(!t)continue;t.liveLocation=null,x.unbindUILocation(e);const n=t.fallback;n&&e.replaceWith(n)}}}maybeLinkifyScriptLocation(e,t,n,i,a){let s=null;const c={lineNumber:i,maxLength:this.maxLength,columnNumber:a?.columnNumber,showColumnNumber:Boolean(a?.showColumnNumber),className:a?.className,tabStop:a?.tabStop,inlineFrameIndex:a?.inlineFrameIndex??0,userMetric:a?.userMetric},{columnNumber:l,className:d=""}=c;if(n&&(s=x.linkifyURL(n,c)),!e||e.isDisposed())return s;const u=e.model(o.DebuggerModel.DebuggerModel);if(!u)return s;const p=t?u.createRawLocationByScriptId(t,i||0,l,c.inlineFrameIndex):u.createRawLocationByURL(n,i||0,l,c.inlineFrameIndex);if(!p)return s;const g={tabStop:a?.tabStop},{link:m,linkInfo:h}=x.createLink(s&&s.textContent?s.textContent:"",d,g);h.enableDecorator=this.useLinkDecorator,h.fallback=s,h.userMetric=a?.userMetric;const k=this.locationPoolByTarget.get(p.debuggerModel.target());if(!k)return s;const L={showColumnNumber:c.showColumnNumber,revealBreakpoint:a?.revealBreakpoint},f=this.onLiveLocationUpdate;r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createLiveLocation(p,this.updateAnchor.bind(this,m,L),k).then((e=>{e&&(h.liveLocation=e,f())}));return this.anchorsByTarget.get(p.debuggerModel.target()).push(m),m}linkifyScriptLocation(e,t,n,i,o){const r=this.maybeLinkifyScriptLocation(e,t,n,i,o),a={lineNumber:i,maxLength:this.maxLength,className:o?.className,columnNumber:o?.columnNumber,showColumnNumber:Boolean(o?.showColumnNumber),inlineFrameIndex:o?.inlineFrameIndex??0,tabStop:o?.tabStop,userMetric:o?.userMetric};return r||x.linkifyURL(n,a)}linkifyRawLocation(e,t,n){return this.linkifyScriptLocation(e.debuggerModel.target(),e.scriptId,t,e.lineNumber,{columnNumber:e.columnNumber,className:n,inlineFrameIndex:e.inlineFrameIndex})}maybeLinkifyConsoleCallFrame(e,t,n){const i={...n,columnNumber:t.columnNumber,inlineFrameIndex:n?.inlineFrameIndex??0};return this.maybeLinkifyScriptLocation(e,t.scriptId,t.url,t.lineNumber,i)}linkifyStackTraceTopFrame(e,t){console.assert(t.callFrames.length>0);const{url:n,lineNumber:i,columnNumber:a}=t.callFrames[0],s=x.linkifyURL(n,{lineNumber:i,columnNumber:a,showColumnNumber:!1,inlineFrameIndex:0,maxLength:this.maxLength,preventClick:!0});if(!e)return s;const c=this.locationPoolByTarget.get(e);if(!c)return console.assert(e.isDisposed()),s;console.assert(!e.isDisposed());const l=e.model(o.DebuggerModel.DebuggerModel),{link:d,linkInfo:u}=x.createLink("","");u.enableDecorator=this.useLinkDecorator,u.fallback=s;const p=this.onLiveLocationUpdate;r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createStackTraceTopFrameLiveLocation(l.createRawLocationsByStackTrace(t),this.updateAnchor.bind(this,d,{showColumnNumber:!1}),c).then((e=>{u.liveLocation=e,p()}));return this.anchorsByTarget.get(e).push(d),d}linkifyCSSLocation(e,t){const{link:n,linkInfo:i}=x.createLink("",t||"",{tabStop:!0});i.enableDecorator=this.useLinkDecorator;const o=this.locationPoolByTarget.get(e.cssModel().target());if(!o)return n;const a=this.onLiveLocationUpdate;r.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().createLiveLocation(e,this.updateAnchor.bind(this,n,{showColumnNumber:!1}),o).then((e=>{i.liveLocation=e,a()}));return this.anchorsByTarget.get(e.cssModel().target()).push(n),n}reset(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e),this.targetAdded(e)}dispose(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e);o.TargetManager.TargetManager.instance().unobserveTargets(this),b.delete(this)}async updateAnchor(t,n,i){x.unbindUILocation(t),n.revealBreakpoint&&x.unbindBreakpoint(t);const o=await i.uiLocation();if(!o){if(i instanceof r.CSSWorkspaceBinding.LiveLocation){const n=i.header();n&&n.ownerNode&&(t.addEventListener("click",(t=>{t.consume(!0),e.Revealer.reveal(n.ownerNode||null)}),!1),x.setTrimmedText(t,"<style>"))}return}x.bindUILocation(t,o),n.revealBreakpoint&&x.bindBreakpoint(t,o);const s=o.linkText(!0,n.showColumnNumber);x.setTrimmedText(t,s,this.maxLength);let c=o.uiSourceCode.url();"application/wasm"===o.uiSourceCode.mimeType()?"number"==typeof o.columnNumber&&(c+=`:0x${o.columnNumber.toString(16)}`):(c+=":"+(o.lineNumber+1),n.showColumnNumber&&"number"==typeof o.columnNumber&&(c+=":"+(o.columnNumber+1))),a.Tooltip.Tooltip.install(t,c),t.classList.toggle("ignore-list-link",await i.isIgnoreListed()),x.updateLinkDecorations(t)}setLiveLocationUpdateCallback(e){this.onLiveLocationUpdate=e}static updateLinkDecorations(e){const t=x.linkInfo(e);if(!t||!t.enableDecorator)return;if(!C||!t.uiLocation)return;t.icon&&t.icon.parentElement&&e.removeChild(t.icon);const n=C.linkIcon(t.uiLocation.uiSourceCode);n&&(n.style.setProperty("margin-right","2px"),e.insertBefore(n,e.firstChild)),t.icon=n}static linkifyURL(e,t){const n=(t=t||{showColumnNumber:!1,inlineFrameIndex:0}).text,i=t.className||"",o=t.lineNumber,s=t.columnNumber,c=t.showColumnNumber,l=t.preventClick,d=t.maxLength||a.UIUtils.MaxLengthForDisplayedURLs,u=t.bypassURLTrimming;if(!e||e.trim().toLowerCase().startsWith("javascript:")){const t=document.createElement("span");return i&&(t.className=i),t.textContent=n||e||f(k.unknown),t}let p=n||r.ResourceUtils.displayNameForURL(e);"number"!=typeof o||n||(p+=":"+(o+1),c&&"number"==typeof s&&(p+=":"+(s+1)));const g={maxLength:d,title:p!==e?e:"",href:e,preventClick:l,tabStop:t.tabStop,bypassURLTrimming:u},{link:m,linkInfo:h}=x.createLink(p,i,g);return o&&(h.lineNumber=o),s&&(h.columnNumber=s),h.userMetric=t?.userMetric,m}static linkifyRevealable(e,t,n,i,o){const r={maxLength:a.UIUtils.MaxLengthForDisplayedURLs,href:n,title:i},{link:s,linkInfo:c}=x.createLink(t,o||"",r);return c.revealable=e,s}static createLink(e,t,n={}){const{maxLength:i,title:o,href:r,preventClick:s,tabStop:c,bypassURLTrimming:l}=n,d=document.createElement("span");t&&(d.className=t),d.classList.add("devtools-link"),o&&a.Tooltip.Tooltip.install(d,o),r&&(d.href=r),e instanceof HTMLElement?d.appendChild(e):l?(d.classList.add("devtools-link-styled-trim"),x.appendTextWithoutHashes(d,e)):x.setTrimmedText(d,e,i);const u={icon:null,enableDecorator:!1,uiLocation:null,liveLocation:null,url:r||null,lineNumber:null,columnNumber:null,inlineFrameIndex:0,revealable:null,fallback:null};return v.set(d,u),s?d.classList.add("devtools-link-prevent-click"):(d.addEventListener("click",(e=>{x.handleClick(e)&&e.consume(!0)}),!1),d.addEventListener("keydown",(e=>{"Enter"===e.key&&x.handleClick(e)&&e.consume(!0)}),!1)),a.ARIAUtils.markAsLink(d),d.tabIndex=c?0:-1,{link:d,linkInfo:u}}static setTrimmedText(e,t,n){if(e.removeChildren(),n&&t.length>n){const i=function(e,t){let n=Math.floor(t/2),i=e.length-Math.ceil(t/2)+1;const o=e.codePointAt(i-1);void 0!==o&&o>=65536&&(i++,n++);const r=e.codePointAt(n-1);void 0!==r&&n>0&&r>=65536&&n--;return[e.substring(0,n),e.substring(n,i),e.substring(i)]}(t,n);x.appendTextWithoutHashes(e,i[0]),x.appendHiddenText(e,i[1]),x.appendTextWithoutHashes(e,i[2])}else x.appendTextWithoutHashes(e,t)}static appendTextWithoutHashes(e,t){const n=c.TextUtils.Utils.splitStringByRegexes(t,[/[a-f0-9]{20,}/g]);for(const t of n)-1===t.regexIndex?a.UIUtils.createTextChild(e,t.value):(a.UIUtils.createTextChild(e,t.value.substring(0,7)),x.appendHiddenText(e,t.value.substring(7)))}static appendHiddenText(e,t){const n=a.UIUtils.createTextChild(e.createChild("span","devtools-link-ellipsis"),"…");S.set(n,t)}static untruncatedNodeText(e){return S.get(e)||e.textContent||""}static linkInfo(e){return e&&v.get(e)||null}static handleClick(e){const t=e.currentTarget;if(a.UIUtils.isBeingEdited(e.target)||t.hasSelection())return!1;const n=x.linkInfo(t);return!!n&&x.invokeFirstAction(n)}static handleClickFromNewComponentLand(e){x.invokeFirstAction(e)}static invokeFirstAction(e){const n=x.linkActions(e);return!!n.length&&(n[0].handler.call(null),e.userMetric&&t.userMetrics.actionTaken(e.userMetric),!0)}static linkHandlerSetting(){return y||(y=e.Settings.Settings.instance().createSetting("openLinkHandler",f(k.auto))),y}static registerLinkHandler(e,t){I.set(e,t),F.instance().update()}static unregisterLinkHandler(e){I.delete(e),F.instance().update()}static uiLocation(e){const t=x.linkInfo(e);return t?t.uiLocation:null}static linkActions(n){const o=[];if(!n)return o;let c=i.DevToolsPath.EmptyUrlString,d=null;if(n.uiLocation)d=n.uiLocation,c=d.uiSourceCode.contentURL();else if(n.url){c=n.url;const t=l.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(c)||l.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.ParsedURL.ParsedURL.urlWithoutHash(c));d=t?t.uiLocation(n.lineNumber||0,n.columnNumber||0):null}const u=c?r.ResourceUtils.resourceForURL(c):null,p=d?d.uiSourceCode:u,g=n.revealable||d||u;if(g){const n=e.Revealer.revealDestination(g);o.push({section:"reveal",title:n?f(k.revealInS,{PH1:n}):f(k.reveal),handler:()=>(g instanceof s.BreakpointManager.BreakpointLocation&&t.userMetrics.breakpointEditDialogRevealedFrom(5),e.Revealer.reveal(g))})}if(p){const e=d?d.lineNumber:n.lineNumber||0;for(const t of I.keys()){const n=I.get(t);if(!n)continue;const i={section:"reveal",title:f(k.openUsingS,{PH1:t}),handler:n.bind(null,p,e)};t===x.linkHandlerSetting().get()?o.unshift(i):o.push(i)}}if((u||n.url)&&(o.push({section:"reveal",title:a.UIUtils.openLinkExternallyLabel(),handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(c)}),o.push({section:"clipboard",title:a.UIUtils.copyLinkAddressLabel(),handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(c)})),d&&d.uiSourceCode){const e=d.uiSourceCode;o.push({section:"clipboard",title:a.UIUtils.copyFileNameLabel(),handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(e.displayName())})}return o}}var T;let U,N;!function(e){let t;!function(e){e.LinkIconChanged="LinkIconChanged"}(t=e.Events||(e.Events={}))}(T||(T={}));class D{static instance(e={forceNew:null}){const{forceNew:t}=e;return U&&!t||(U=new D),U}appendApplicableItems(e,t,n){let i=n;for(;i&&!v.get(i);)i=i.parentNodeOrShadowHost();const o=i,r=x.linkInfo(o);if(!r)return;const a=x.linkActions(r);for(const e of a)t.section(e.section).appendItem(e.title,e.handler)}}class F{element;constructor(){this.element=document.createElement("select"),this.element.classList.add("chrome-select"),this.element.addEventListener("change",this.onChange.bind(this),!1),this.update()}static instance(e={forceNew:null}){const{forceNew:t}=e;return N&&!t||(N=new F),N}update(){this.element.removeChildren();const e=[...I.keys()];e.unshift(f(k.auto));for(const t of e){const e=document.createElement("option");e.textContent=t,e.selected=t===x.linkHandlerSetting().get(),this.element.appendChild(e)}this.element.disabled=e.length<=1}onChange(e){if(!e.target)return;const t=e.target.value;x.linkHandlerSetting().set(t)}settingElement(){return a.SettingsUI.createCustomSetting(f(k.linkHandling),this.element)}}let R,M=!1;M||(M=!0,window.addEventListener("linkifieractivated",(function(e){const t=e;x.handleClickFromNewComponentLand(t.data)})));class H{static instance(e={forceNew:null}){const{forceNew:t}=e;return R&&!t||(R=new H),R}appendApplicableItems(n,i,r){const s=r,c=s.contentURL();if(c){c.startsWith("file://")||i.revealSection().appendItem(a.UIUtils.openLinkExternallyLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(c.endsWith(":formatted")?e.ParsedURL.ParsedURL.slice(c,0,c.lastIndexOf(":")):c)));for(const e of I.keys()){const t=I.get(e);t&&i.revealSection().appendItem(f(k.openUsingS,{PH1:e}),t.bind(null,s,0))}s instanceof o.NetworkRequest.NetworkRequest||(i.clipboardSection().appendItem(a.UIUtils.copyLinkAddressLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(c))),i.clipboardSection().appendItem(a.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(s.displayName()))))}}}var B=Object.freeze({__proto__:null,Linkifier:x,get LinkDecorator(){return T},LinkContextMenuProvider:D,LinkHandlerSettingUI:F,ContentProviderContextMenuProvider:H});const A=new CSSStyleSheet;A.replaceSync(":host{display:inline}.stack-preview-async-description{padding:3px 0 1px;font-style:italic}.stack-preview-container .ignore-list-link{opacity:60%}.stack-preview-container > tr{height:16px;line-height:16px}.stack-preview-container td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-inline:2px}.stack-preview-container .function-name{max-width:80em}.stack-preview-container:not(.show-hidden-rows) > tr.hidden-row{display:none}.stack-preview-container > tr.show-all-link,\n.stack-preview-container > tr.show-less-link{font-style:italic}.stack-preview-container.show-hidden-rows > tr.show-all-link{display:none}.stack-preview-container:not(.show-hidden-rows) > tr.show-less-link{display:none}\n/*# sourceURL=jsUtils.css */\n");const P={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showSMoreFrames:"{n, plural, =1 {Show # more frame} other {Show # more frames}}",showLess:"Show less",unknownSource:"unknown"},E=n.i18n.registerUIStrings("ui/legacy/components/utils/JSPresentationUtils.ts",P),W=n.i18n.getLocalizedString.bind(void 0,E);function _(e,t){const n=new a.ContextMenu.ContextMenu(t);t.consume(!0);const i=x.uiLocation(e);i&&r.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(i.uiSourceCode)&&(r.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(i.uiSourceCode.url())?n.debugSection().appendItem(W(P.removeFromIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(i.uiSourceCode))):n.debugSection().appendItem(W(P.addToIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(i.uiSourceCode)))),n.appendApplicableItems(t),n.show()}function z(t,n,i,s,c){const l=[];if(c){const t=new e.Throttler.Throttler(100);i.setLiveLocationUpdateCallback((()=>t.schedule((async()=>function(e,t){let n=0,i=t.length;for(let e=t.length-1;e>=0;e--){const o=t[e];if("link"in o&&o.link){const e=x.uiLocation(o.link);e&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(e.uiSourceCode)&&(o.ignoreListHide=!0),o.ignoreListHide&&n++}"asyncDescription"in o&&(n>0&&n===i-e-1&&(o.ignoreListHide=!0),i=e,n=0)}e(t)}(c,l)))))}function d(e,t){let c=null;t&&(c={asyncDescription:a.UIUtils.asyncStackTraceLabel(e.description,t),ignoreListHide:!1},l.push(c));let d=0,u=!1;for(const t of e.callFrames){let e=!1;const c=a.UIUtils.beautifyFunctionName(t.functionName),p=i.maybeLinkifyConsoleCallFrame(n,t,{tabStop:Boolean(s),inlineFrameIndex:0,revealBreakpoint:u});if(p){p.addEventListener("contextmenu",_.bind(null,p));const t=x.uiLocation(p);t&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(t.uiSourceCode)&&(e=!0),p.textContent||(p.textContent=W(P.unknownSource))}e&&++d,l.push({functionName:c,link:p,ignoreListHide:e}),u=[o.DebuggerModel.COND_BREAKPOINT_SOURCE_URL,o.DebuggerModel.LOGPOINT_SOURCE_URL].includes(t.url)}c&&d>0&&d===e.callFrames.length&&(c.ignoreListHide=!0)}d(t);let u=t.callFrames;for(let e=t.parent;e;e=e.parent)e.callFrames.length&&d(e,u),u=e.callFrames;return l}function j(e,t){e.removeChildren();let n=0;const i=[];for(const o of t){const t=e.createChild("tr");"asyncDescription"in o?(t.createChild("td").textContent="\n",t.createChild("td","stack-preview-async-description").textContent=o.asyncDescription,t.createChild("td"),t.createChild("td")):(t.createChild("td").textContent="\n",t.createChild("td","function-name").textContent=o.functionName,t.createChild("td").textContent=" @ ",o.link&&(t.createChild("td").appendChild(o.link),i.push(o.link)),o.ignoreListHide&&++n),o.ignoreListHide&&t.classList.add("hidden-row"),e.appendChild(t)}if(n){const t=e.createChild("tr","show-all-link");t.createChild("td").textContent="\n";const i=t.createChild("td");i.colSpan=4;const o=i.createChild("span","link");o.textContent=W(P.showSMoreFrames,{n:n}),o.addEventListener("click",(()=>{e.classList.add("show-hidden-rows")}),!1);const r=e.createChild("tr","show-less-link");r.createChild("td").textContent="\n";const a=r.createChild("td");a.colSpan=4;const s=a.createChild("span","link");s.textContent=W(P.showLess),s.addEventListener("click",(()=>{e.classList.remove("show-hidden-rows")}),!1)}return i}var O=Object.freeze({__proto__:null,buildStackTraceRows:z,buildStackTracePreviewContents:function(e,t,n={stackTrace:void 0,tabStops:void 0}){const{stackTrace:i,tabStops:o}=n,r=document.createElement("span");r.classList.add("monospace"),r.style.display="inline-block";const s=a.Utils.createShadowRootWithCoreStyles(r,{cssFile:[A],delegatesFocus:void 0}).createChild("table","stack-preview-container");if(!i)return{element:r,links:[]};const c=j.bind(null,s);return{element:r,links:j(s,z(i,e,t,o,c))}}});var K=Object.freeze({__proto__:null,reload:function(){a.DockController.DockController.instance().canDock()&&"undocked"===a.DockController.DockController.instance().dockSide()&&t.InspectorFrontendHost.InspectorFrontendHostInstance.setIsDocked(!0,(function(){})),t.InspectorFrontendHost.InspectorFrontendHostInstance.reattach((()=>window.location.reload()))}});const $={websocketDisconnected:"WebSocket disconnected"},q=n.i18n.registerUIStrings("ui/legacy/components/utils/TargetDetachedDialog.ts",$),J=n.i18n.getLocalizedString.bind(void 0,q);class G extends o.SDKModel.SDKModel{static hideCrashedDialog;constructor(e){super(e),e.registerInspectorDispatcher(this),e.inspectorAgent().invoke_enable(),e.parentTarget()?.type()===o.Target.Type.Browser&&G.hideCrashedDialog&&(G.hideCrashedDialog.call(null),G.hideCrashedDialog=null)}detached({reason:e}){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(e)}static webSocketConnectionLost(){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(J($.websocketDisconnected))}targetCrashed(){if(G.hideCrashedDialog)return;const e=this.target().parentTarget();if(e&&e.type()!==o.Target.Type.Browser)return;const t=new a.Dialog.Dialog;t.setSizeBehavior("MeasureContent"),t.addCloseButton(),t.setDimmed(!0),G.hideCrashedDialog=t.hide.bind(t),new a.TargetCrashedScreen.TargetCrashedScreen((()=>{G.hideCrashedDialog=null})).show(t.contentElement),t.show()}targetReloadedAfterCrash(){this.target().runtimeAgent().invoke_runIfWaitingForDebugger(),G.hideCrashedDialog&&(G.hideCrashedDialog.call(null),G.hideCrashedDialog=null)}}o.SDKModel.SDKModel.register(G,{capabilities:o.Target.Capability.Inspector,autostart:!0});var V=Object.freeze({__proto__:null,TargetDetachedDialog:G});export{h as ImagePreview,O as JSPresentationUtils,B as Linkifier,K as Reload,V as TargetDetachedDialog};
import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/host/host.js";import*as n from"../../../../core/i18n/i18n.js";import*as i from"../../../../core/platform/platform.js";import*as o from"../../../../core/sdk/sdk.js";import*as r from"../../../../models/bindings/bindings.js";import*as a from"../../../visual_logging/visual_logging.js";import*as s from"../../legacy.js";import*as c from"../../../../models/breakpoints/breakpoints.js";import*as l from"../../../../models/text_utils/text_utils.js";import*as d from"../../../../models/workspace/workspace.js";const u=new CSSStyleSheet;u.replaceSync(".image-preview-container{background:transparent;text-align:center;border-spacing:0}.image-preview-container img{margin:6px 0;max-width:100px;max-height:100px;background-image:var(--image-file-checker);user-select:text;vertical-align:top;-webkit-user-drag:auto}.image-container{padding:0}.image-container > div{min-height:50px;display:flex;align-items:center;justify-content:center;cursor:pointer}.image-preview-container .row{line-height:1.2;vertical-align:baseline}.image-preview-container .title{padding-right:0.5em;text-align:right;color:var(--sys-color-token-subtle);white-space:nowrap}.image-preview-container .description{white-space:nowrap;text-align:left;color:var(--sys-color-on-surface)}.image-preview-container .description-link{max-width:20em}.image-preview-container .source-link{white-space:normal;word-break:break-all;color:var(--sys-color-primary);cursor:pointer}\n/*# sourceURL=imagePreview.css */\n");const p={unknownSource:"unknown source",imageFromS:"Image from {PH1}",fileSize:"File size:",intrinsicSize:"Intrinsic size:",renderedSize:"Rendered size:",currentSource:"Current source:",renderedAspectRatio:"Rendered aspect ratio:",intrinsicAspectRatio:"Intrinsic aspect ratio:"},g=n.i18n.registerUIStrings("ui/legacy/components/utils/ImagePreview.ts",p),m=n.i18n.getLocalizedString.bind(void 0,g);function h(t){return null!==t&&t.resourceType()===e.ResourceType.resourceTypes.Image}var k=Object.freeze({__proto__:null,ImagePreview:class{static async build(e,n,r,a={precomputedFeatures:void 0,imageAltText:void 0}){const{precomputedFeatures:s,imageAltText:c}=a,l=e.model(o.ResourceTreeModel.ResourceTreeModel);if(!l)return null;let d=l.resourceForURL(n),g=n;if(!h(d)&&s&&s.currentSrc&&(g=s.currentSrc,d=l.resourceForURL(g)),!d||!h(d))return null;const k=d,L=d.displayName,b=d.content?d.content:d.url.split("base64,")[1],f=d.contentSize(),C=f||i.StringUtilities.base64ToSize(b),v=C>0?i.NumberUtilities.bytesToString(C):"";return new Promise((e=>{const n=document.createElement("img");n.addEventListener("load",(function(){const o=document.createElement("div"),a=o.attachShadow({mode:"open"});a.adoptedStyleSheets=[u];const c=a.createChild("table");c.className="image-preview-container";const l=c.createChild("tr").createChild("td","image-container");l.colSpan=2;const d=l.createChild("div");d.title=L,d.appendChild(n),d.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(g)}));const h=n.naturalWidth,k=n.naturalHeight,b=s?s.renderedWidth:h,f=s?s.renderedHeight:k;if(r){const e=c.createChild("tr","row");e.createChild("td","title").textContent=m(p.renderedSize),e.createChild("td","description").textContent=`${b} × ${f} px`;const t=c.createChild("tr","row");if(t.createChild("td","title").textContent=m(p.renderedAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(b,f),f!==k||b!==h){const e=c.createChild("tr","row");e.createChild("td","title").textContent=m(p.intrinsicSize),e.createChild("td","description").textContent=`${h} × ${k} px`;const t=c.createChild("tr","row");t.createChild("td","title").textContent=m(p.intrinsicAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(h,k)}}const C=c.createChild("tr","row");C.createChild("td","title").textContent=m(p.fileSize),C.createChild("td","description").textContent=v;const w=c.createChild("tr","row");w.createChild("td","title").textContent=m(p.currentSource);const I=i.StringUtilities.trimMiddle(g,100),S=w.createChild("td","description description-link").createChild("span","source-link");S.textContent=I,S.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(g)})),e(o)}),!1),n.addEventListener("error",(()=>e(null)),!1),c&&(n.alt=c),k.populateImageSource(n)}))}static async loadDimensionsForNode(e){if(!e.nodeName()||"img"!==e.nodeName().toLowerCase())return;const t=await e.resolveToObject("");if(!t)return;const n=await t.callFunctionJSON((function(){return{renderedWidth:this.width,renderedHeight:this.height,currentSrc:this.currentSrc}}),void 0);return t.release(),n}static defaultAltTextForImageURL(t){const n=new e.ParsedURL.ParsedURL(t),i=n.isValid?n.displayName:m(p.unknownSource);return m(p.imageFromS,{PH1:i})}}});const L=new CSSStyleSheet;L.replaceSync(":host{display:inline-block;width:100%}.stack-preview-async-description{padding:3px 0 1px;font-style:italic}.stack-preview-container{display:block;width:100%}.stack-preview-container .ignore-list-link{opacity:60%}.stack-preview-container > tr{height:16px;line-height:16px}.stack-preview-container td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-inline:2px}.stack-preview-container td.link{width:100%;max-width:0}.stack-preview-container .function-name{max-width:80em}.stack-preview-container:not(.show-hidden-rows) > tr.hidden-row{display:none}.stack-preview-container > tr.show-all-link,\n.stack-preview-container > tr.show-less-link{font-style:italic}.stack-preview-container.show-hidden-rows > tr.show-all-link{display:none}.stack-preview-container:not(.show-hidden-rows) > tr.show-less-link{display:none}\n/*# sourceURL=jsUtils.css */\n");const b={unknown:"(unknown)",auto:"auto",revealInS:"Reveal in {PH1}",reveal:"Reveal",openUsingS:"Open using {PH1}",linkHandling:"Link handling:"},f=n.i18n.registerUIStrings("ui/legacy/components/utils/Linkifier.ts",b),C=n.i18n.getLocalizedString.bind(void 0,f),v=new Set;let w=null;const I=new WeakMap,S=new WeakMap,x=new WeakMap,y=new Map;let T,U;class N extends e.ObjectWrapper.ObjectWrapper{maxLength;anchorsByTarget;locationPoolByTarget;useLinkDecorator;constructor(e,t){super(),this.maxLength=e||s.UIUtils.MaxLengthForDisplayedURLs,this.anchorsByTarget=new Map,this.locationPoolByTarget=new Map,this.useLinkDecorator=Boolean(t),v.add(this),o.TargetManager.TargetManager.instance().observeTargets(this)}static setLinkDecorator(e){console.assert(!w,"Cannot re-register link decorator."),w=e,e.addEventListener("LinkIconChanged",(function(e){const t=e.data,n=I.get(t)||[];for(const e of n)N.updateLinkDecorations(e)}));for(const e of v)e.updateAllAnchorDecorations()}updateAllAnchorDecorations(){for(const e of this.anchorsByTarget.values())for(const t of e)N.updateLinkDecorations(t)}static bindUILocation(e,t){const n=N.linkInfo(e);if(!n)return;if(n.uiLocation=t,!t)return;const i=t.uiSourceCode;let o=I.get(i);o||(o=new Set,I.set(i,o)),o.add(e)}static unbindUILocation(e){const t=N.linkInfo(e);if(!t||!t.uiLocation)return;const n=t.uiLocation.uiSourceCode;t.uiLocation=null;const i=I.get(n);i&&i.delete(e)}static bindBreakpoint(e,t){const n=N.linkInfo(e);if(!n)return;const i=c.BreakpointManager.BreakpointManager.instance().findBreakpoint(t);i&&(n.revealable=i)}static unbindBreakpoint(e){const t=N.linkInfo(e);t&&t.revealable&&(t.revealable=null)}targetAdded(e){this.anchorsByTarget.set(e,[]),this.locationPoolByTarget.set(e,new r.LiveLocation.LiveLocationPool)}targetRemoved(e){const t=this.locationPoolByTarget.get(e);if(this.locationPoolByTarget.delete(e),!t)return;t.disposeAll();const n=this.anchorsByTarget.get(e);if(n){this.anchorsByTarget.delete(e);for(const e of n){const t=N.linkInfo(e);if(!t)continue;t.liveLocation=null,N.unbindUILocation(e);const n=t.fallback;n&&e.replaceWith(n)}}}maybeLinkifyScriptLocation(e,t,n,i,a){let s=null;const c={lineNumber:i,maxLength:this.maxLength,columnNumber:a?.columnNumber,showColumnNumber:Boolean(a?.showColumnNumber),className:a?.className,tabStop:a?.tabStop,inlineFrameIndex:a?.inlineFrameIndex??0,userMetric:a?.userMetric},{columnNumber:l,className:d=""}=c;if(n&&(s=N.linkifyURL(n,c)),!e||e.isDisposed())return s;const u=e.model(o.DebuggerModel.DebuggerModel);if(!u)return s;const p=t?u.createRawLocationByScriptId(t,i||0,l,c.inlineFrameIndex):u.createRawLocationByURL(n,i||0,l,c.inlineFrameIndex,!0);if(!p)return s;const g={tabStop:a?.tabStop},{link:m,linkInfo:h}=N.createLink(s&&s.textContent?s.textContent:"",d,g);h.enableDecorator=this.useLinkDecorator,h.fallback=s,h.userMetric=a?.userMetric;const k=this.locationPoolByTarget.get(p.debuggerModel.target());if(!k)return s;const L={showColumnNumber:c.showColumnNumber??!1,revealBreakpoint:a?.revealBreakpoint};r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createLiveLocation(p,(async e=>{await this.updateAnchor(m,L,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),k).then((e=>{e&&(h.liveLocation=e)}));return this.anchorsByTarget.get(p.debuggerModel.target()).push(m),m}linkifyScriptLocation(e,t,n,i,o){const r=this.maybeLinkifyScriptLocation(e,t,n,i,o),a={lineNumber:i,maxLength:this.maxLength,className:o?.className,columnNumber:o?.columnNumber,showColumnNumber:Boolean(o?.showColumnNumber),inlineFrameIndex:o?.inlineFrameIndex??0,tabStop:o?.tabStop,userMetric:o?.userMetric};return r||N.linkifyURL(n,a)}linkifyRawLocation(e,t,n){return this.linkifyScriptLocation(e.debuggerModel.target(),e.scriptId,t,e.lineNumber,{columnNumber:e.columnNumber,className:n,inlineFrameIndex:e.inlineFrameIndex})}maybeLinkifyConsoleCallFrame(e,t,n){const i={...n,columnNumber:t.columnNumber,inlineFrameIndex:n?.inlineFrameIndex??0};return this.maybeLinkifyScriptLocation(e,t.scriptId,t.url,t.lineNumber,i)}linkifyStackTraceTopFrame(e,t){console.assert(t.callFrames.length>0);const{url:n,lineNumber:i,columnNumber:a}=t.callFrames[0],s=N.linkifyURL(n,{lineNumber:i,columnNumber:a,showColumnNumber:!1,inlineFrameIndex:0,maxLength:this.maxLength,preventClick:!0});if(!e)return s;const c=this.locationPoolByTarget.get(e);if(!c)return console.assert(e.isDisposed()),s;console.assert(!e.isDisposed());const l=e.model(o.DebuggerModel.DebuggerModel),{link:d,linkInfo:u}=N.createLink("","");u.enableDecorator=this.useLinkDecorator,u.fallback=s;const p={showColumnNumber:!1};r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createStackTraceTopFrameLiveLocation(l.createRawLocationsByStackTrace(t),(async e=>{await this.updateAnchor(d,p,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),c).then((e=>{u.liveLocation=e}));return this.anchorsByTarget.get(e).push(d),d}linkifyCSSLocation(e,t){const{link:n,linkInfo:i}=N.createLink("",t||"",{tabStop:!0});i.enableDecorator=this.useLinkDecorator;const o=this.locationPoolByTarget.get(e.cssModel().target());if(!o)return n;const a={showColumnNumber:!1};r.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().createLiveLocation(e,(async e=>{await this.updateAnchor(n,a,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),o).then((e=>{i.liveLocation=e}));return this.anchorsByTarget.get(e.cssModel().target()).push(n),n}reset(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e),this.targetAdded(e)}dispose(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e);o.TargetManager.TargetManager.instance().unobserveTargets(this),v.delete(this)}async updateAnchor(t,n,i){N.unbindUILocation(t),n.revealBreakpoint&&N.unbindBreakpoint(t);const o=await i.uiLocation();if(!o){if(i instanceof r.CSSWorkspaceBinding.LiveLocation){const n=i.header();n&&n.ownerNode&&(t.addEventListener("click",(t=>{t.consume(!0),e.Revealer.reveal(n.ownerNode||null)}),!1),N.setTrimmedText(t,"<style>"))}return t.classList.add("invalid-link"),void t.removeAttribute("role")}N.bindUILocation(t,o),n.revealBreakpoint&&N.bindBreakpoint(t,o);const a=o.linkText(!0,n.showColumnNumber);N.setTrimmedText(t,a,this.maxLength);let c=o.uiSourceCode.url();"application/wasm"===o.uiSourceCode.mimeType()?"number"==typeof o.columnNumber&&(c+=`:0x${o.columnNumber.toString(16)}`):(c+=":"+(o.lineNumber+1),n.showColumnNumber&&"number"==typeof o.columnNumber&&(c+=":"+(o.columnNumber+1))),s.Tooltip.Tooltip.install(t,c),t.classList.toggle("ignore-list-link",await i.isIgnoreListed()),N.updateLinkDecorations(t)}static updateLinkDecorations(e){const t=N.linkInfo(e);if(!t||!t.enableDecorator)return;if(!w||!t.uiLocation)return;t.icon&&t.icon.parentElement&&e.removeChild(t.icon);const n=w.linkIcon(t.uiLocation.uiSourceCode);n&&(n.style.setProperty("margin-right","2px"),e.insertBefore(n,e.firstChild)),t.icon=n}static linkifyURL(t,n){const i=(n=n||{showColumnNumber:!1,inlineFrameIndex:0}).text,o=n.className||"",a=n.lineNumber,c=n.columnNumber,l=n.showColumnNumber,d=n.preventClick,u=n.maxLength||s.UIUtils.MaxLengthForDisplayedURLs,p=n.bypassURLTrimming;if(!t||e.ParsedURL.schemeIs(t,"javascript:")){const e=document.createElement("span");return o&&(e.className=o),e.textContent=i||t||C(b.unknown),e}let g=i||r.ResourceUtils.displayNameForURL(t);"number"!=typeof a||i||(g+=":"+(a+1),l&&"number"==typeof c&&(g+=":"+(c+1)));const m={maxLength:u,title:g!==t?t:"",href:t,preventClick:d,tabStop:n.tabStop,bypassURLTrimming:p},{link:h,linkInfo:k}=N.createLink(g,o,m);return a&&(k.lineNumber=a),c&&(k.columnNumber=c),k.userMetric=n?.userMetric,h}static linkifyRevealable(e,t,n,i,o){const r={maxLength:s.UIUtils.MaxLengthForDisplayedURLs,href:n,title:i},{link:a,linkInfo:c}=N.createLink(t,o||"",r);return c.revealable=e,a}static createLink(e,t,n={}){const{maxLength:i,title:o,href:r,preventClick:a,tabStop:c,bypassURLTrimming:l}=n,d=document.createElement("button");t&&(d.className=t),d.classList.add("devtools-link","text-button","link-style"),o&&s.Tooltip.Tooltip.install(d,o),r&&(d.href=r),e instanceof HTMLElement?d.appendChild(e):l?(d.classList.add("devtools-link-styled-trim"),N.appendTextWithoutHashes(d,e)):N.setTrimmedText(d,e,i);const u={icon:null,enableDecorator:!1,uiLocation:null,liveLocation:null,url:r||null,lineNumber:null,columnNumber:null,inlineFrameIndex:0,revealable:null,fallback:null};return S.set(d,u),a?d.classList.add("devtools-link-prevent-click"):d.addEventListener("click",(e=>{N.handleClick(e)&&e.consume(!0)}),!1),s.ARIAUtils.markAsLink(d),d.tabIndex=c?0:-1,{link:d,linkInfo:u}}static setTrimmedText(e,t,n){if(e.removeChildren(),n&&t.length>n){const i=function(e,t){let n=Math.floor(t/2),i=e.length-Math.ceil(t/2)+1;const o=e.codePointAt(i-1);void 0!==o&&o>=65536&&(i++,n++);const r=e.codePointAt(n-1);void 0!==r&&n>0&&r>=65536&&n--;return[e.substring(0,n),e.substring(n,i),e.substring(i)]}(t,n);N.appendTextWithoutHashes(e,i[0]),N.appendHiddenText(e,i[1]),N.appendTextWithoutHashes(e,i[2])}else N.appendTextWithoutHashes(e,t)}static appendTextWithoutHashes(e,t){const n=l.TextUtils.Utils.splitStringByRegexes(t,[/[a-f0-9]{20,}/g]);for(const t of n)-1===t.regexIndex?s.UIUtils.createTextChild(e,t.value):(s.UIUtils.createTextChild(e,t.value.substring(0,7)),N.appendHiddenText(e,t.value.substring(7)))}static appendHiddenText(e,t){const n=s.UIUtils.createTextChild(e.createChild("span","devtools-link-ellipsis"),"…");x.set(n,t)}static untruncatedNodeText(e){return x.get(e)||e.textContent||""}static linkInfo(e){return e&&S.get(e)||null}static handleClick(e){const t=e.currentTarget;if(s.UIUtils.isBeingEdited(e.target)||t.hasSelection())return!1;const n=N.linkInfo(t);return!!n&&N.invokeFirstAction(n)}static handleClickFromNewComponentLand(e){N.invokeFirstAction(e)}static invokeFirstAction(e){const n=N.linkActions(e);return!!n.length&&(n[0].handler.call(null),e.userMetric&&t.userMetrics.actionTaken(e.userMetric),!0)}static linkHandlerSetting(){return T||(T=e.Settings.Settings.instance().createSetting("open-link-handler",C(b.auto))),T}static registerLinkHandler(e,t){y.set(e,t),F.instance().update()}static unregisterLinkHandler(e){y.delete(e),F.instance().update()}static uiLocation(e){const t=N.linkInfo(e);return t?t.uiLocation:null}static linkActions(n){const o=[];if(!n)return o;let a=i.DevToolsPath.EmptyUrlString,l=null;if(n.uiLocation)l=n.uiLocation,a=l.uiSourceCode.contentURL();else if(n.url){a=n.url;const t=d.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(a)||d.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.ParsedURL.ParsedURL.urlWithoutHash(a));l=t?t.uiLocation(n.lineNumber||0,n.columnNumber||0):null}const u=a?r.ResourceUtils.resourceForURL(a):null,p=l?l.uiSourceCode:u,g=n.revealable||l||u;if(g){const n=e.Revealer.revealDestination(g);o.push({section:"reveal",title:n?C(b.revealInS,{PH1:n}):C(b.reveal),jslogContext:"reveal",handler:()=>(g instanceof c.BreakpointManager.BreakpointLocation&&t.userMetrics.breakpointEditDialogRevealedFrom(5),e.Revealer.reveal(g))})}if(p){const e=l?l.lineNumber:n.lineNumber||0;for(const t of y.keys()){const n=y.get(t);if(!n)continue;const i={section:"reveal",title:C(b.openUsingS,{PH1:t}),jslogContext:"open-using",handler:n.bind(null,p,e)};t===N.linkHandlerSetting().get()?o.unshift(i):o.push(i)}}if((u||n.url)&&(o.push({section:"reveal",title:s.UIUtils.openLinkExternallyLabel(),jslogContext:"open-in-new-tab",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(a)}),o.push({section:"clipboard",title:s.UIUtils.copyLinkAddressLabel(),jslogContext:"copy-link-address",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(a)})),l&&l.uiSourceCode){const e=l.uiSourceCode;o.push({section:"clipboard",title:s.UIUtils.copyFileNameLabel(),jslogContext:"copy-file-name",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(e.displayName())})}return o}}class F{element;constructor(){this.element=document.createElement("select"),this.element.classList.add("chrome-select"),this.element.addEventListener("change",this.onChange.bind(this),!1),this.update()}static instance(e={forceNew:null}){const{forceNew:t}=e;return U&&!t||(U=new F),U}update(){this.element.removeChildren();const e=[...y.keys()];e.unshift(C(b.auto));for(const t of e){const e=document.createElement("option");e.textContent=t,e.selected=t===N.linkHandlerSetting().get(),this.element.appendChild(e)}this.element.disabled=e.length<=1}onChange(e){if(!e.target)return;const t=e.target.value;N.linkHandlerSetting().set(t)}settingElement(){return s.SettingsUI.createCustomSetting(C(b.linkHandling),this.element)}}let D=!1;D||(D=!0,window.addEventListener("linkifieractivated",(function(e){const t=e;N.handleClickFromNewComponentLand(t.data)})));var R=Object.freeze({__proto__:null,Linkifier:N,LinkContextMenuProvider:class{appendApplicableItems(e,t,n){let i=n;for(;i&&!S.get(i);)i=i.parentNodeOrShadowHost();const o=i,r=N.linkInfo(o);if(!r)return;const a=N.linkActions(r);for(const e of a)t.section(e.section).appendItem(e.title,e.handler,{jslogContext:e.jslogContext})}},LinkHandlerSettingUI:F,ContentProviderContextMenuProvider:class{appendApplicableItems(n,i,r){const a=r.contentURL();if(a){e.ParsedURL.schemeIs(a,"file:")||i.revealSection().appendItem(s.UIUtils.openLinkExternallyLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(a.endsWith(":formatted")?e.ParsedURL.ParsedURL.slice(a,0,a.lastIndexOf(":")):a)),{jslogContext:"open-in-new-tab"});for(const e of y.keys()){const t=y.get(e);t&&i.revealSection().appendItem(C(b.openUsingS,{PH1:e}),t.bind(null,r,0),{jslogContext:"open-using"})}r instanceof o.NetworkRequest.NetworkRequest||(i.clipboardSection().appendItem(s.UIUtils.copyLinkAddressLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(a)),{jslogContext:"copy-link-address"}),r instanceof d.UISourceCode.UISourceCode?i.clipboardSection().appendItem(s.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(r.displayName())),{jslogContext:"copy-file-name"}):i.clipboardSection().appendItem(s.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(r.displayName)),{jslogContext:"copy-file-name"}))}}}});const M={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showSMoreFrames:"{n, plural, =1 {Show # more frame} other {Show # more frames}}",showLess:"Show less",unknownSource:"unknown"},H=n.i18n.registerUIStrings("ui/legacy/components/utils/JSPresentationUtils.ts",M),B=n.i18n.getLocalizedString.bind(void 0,H);function P(e,t){const n=new s.ContextMenu.ContextMenu(t);t.consume(!0);const i=N.uiLocation(e);i&&r.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(i.uiSourceCode)&&(r.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(i.uiSourceCode.url())?n.debugSection().appendItem(B(M.removeFromIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(i.uiSourceCode)),{jslogContext:"remove-from-ignore-list"}):n.debugSection().appendItem(B(M.addToIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(i.uiSourceCode)),{jslogContext:"add-to-ignore-list"})),n.appendApplicableItems(t),n.show()}function A(t,n,i,c,l){const d=[];if(l){const t=new e.Throttler.Throttler(100);i.addEventListener("liveLocationUpdated",(()=>{t.schedule((async()=>function(e,t){let n=0,i=t.length;for(let e=t.length-1;e>=0;e--){const o=t[e];if("link"in o&&o.link){const e=N.uiLocation(o.link);e&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(e.uiSourceCode)&&(o.ignoreListHide=!0),o.ignoreListHide&&n++}"asyncDescription"in o&&(n>0&&n===i-e-1&&(o.ignoreListHide=!0),i=e,n=0)}e(t)}(l,d)))}))}function u(e,t=void 0){let l=null;t&&(l={asyncDescription:s.UIUtils.asyncStackTraceLabel(e.description,t),ignoreListHide:!1},d.push(l));let u=0,p=!1;for(const t of e.callFrames){let e=!1;const l=s.UIUtils.beautifyFunctionName(t.functionName),g=i.maybeLinkifyConsoleCallFrame(n,t,{tabStop:Boolean(c),inlineFrameIndex:0,revealBreakpoint:p});if(g){g.setAttribute("jslog",`${a.link("stack-trace").track({click:!0})}`),g.addEventListener("contextmenu",P.bind(null,g));const t=N.uiLocation(g);t&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(t.uiSourceCode)&&(e=!0),g.textContent||(g.textContent=B(M.unknownSource))}e&&++u,d.push({functionName:l,link:g,ignoreListHide:e}),p=[o.DebuggerModel.COND_BREAKPOINT_SOURCE_URL,o.DebuggerModel.LOGPOINT_SOURCE_URL].includes(t.url)}l&&u>0&&u===e.callFrames.length&&(l.ignoreListHide=!0)}u(t);let p=t.callFrames;for(let e=t.parent;e;e=e.parent)e.callFrames.length&&u(e,p),p=e.callFrames;return d}function j(e,t){e.removeChildren();let n=0;const i=[];for(const o of t){const t=e.createChild("tr");"asyncDescription"in o?(t.createChild("td").textContent="\n",t.createChild("td","stack-preview-async-description").textContent=o.asyncDescription,t.createChild("td"),t.createChild("td")):(t.createChild("td").textContent="\n",t.createChild("td","function-name").textContent=o.functionName,t.createChild("td").textContent=" @ ",o.link&&(t.createChild("td","link").appendChild(o.link),i.push(o.link)),o.ignoreListHide&&++n),o.ignoreListHide&&t.classList.add("hidden-row"),e.appendChild(t)}if(n){const t=e.createChild("tr","show-all-link");t.createChild("td").textContent="\n";const i=t.createChild("td");i.colSpan=4;const o=i.createChild("span","link");o.textContent=B(M.showSMoreFrames,{n:n}),o.addEventListener("click",(()=>{e.classList.add("show-hidden-rows"),s.GlassPane.GlassPane.containerMoved(e)}),!1);const r=e.createChild("tr","show-less-link");r.createChild("td").textContent="\n";const a=r.createChild("td");a.colSpan=4;const c=a.createChild("span","link");c.textContent=B(M.showLess),c.addEventListener("click",(()=>{e.classList.remove("show-hidden-rows"),s.GlassPane.GlassPane.containerMoved(e)}),!1)}return i}var E=Object.freeze({__proto__:null,buildStackTraceRows:A,buildStackTracePreviewContents:function(e,t,n={stackTrace:void 0,tabStops:void 0}){const{stackTrace:i,tabStops:o}=n,r=document.createElement("span");r.classList.add("monospace"),r.classList.add("stack-preview-container"),r.style.display="inline-block";const a=s.Utils.createShadowRootWithCoreStyles(r,{cssFile:[L],delegatesFocus:void 0}).createChild("table","stack-preview-container");if(!i)return{element:r,links:[]};const c=j.bind(null,a);return{element:r,links:j(a,A(i,e,t,o,c))}}});var _=Object.freeze({__proto__:null,reload:function(){s.DockController.DockController.instance().canDock()&&"undocked"===s.DockController.DockController.instance().dockSide()&&t.InspectorFrontendHost.InspectorFrontendHostInstance.setIsDocked(!0,(function(){})),t.InspectorFrontendHost.InspectorFrontendHostInstance.reattach((()=>window.location.reload()))}});const W={websocketDisconnected:"WebSocket disconnected"},z=n.i18n.registerUIStrings("ui/legacy/components/utils/TargetDetachedDialog.ts",W),O=n.i18n.getLocalizedString.bind(void 0,z);class $ extends o.SDKModel.SDKModel{static hideCrashedDialog;constructor(e){super(e),e.registerInspectorDispatcher(this),e.inspectorAgent().invoke_enable(),e.parentTarget()?.type()===o.Target.Type.Browser&&$.hideCrashedDialog&&($.hideCrashedDialog.call(null),$.hideCrashedDialog=null)}detached({reason:e}){s.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(e)}static webSocketConnectionLost(){s.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(O(W.websocketDisconnected))}targetCrashed(){if($.hideCrashedDialog)return;const e=this.target().parentTarget();if(e&&e.type()!==o.Target.Type.Browser)return;const t=new s.Dialog.Dialog("target-crashed");t.setSizeBehavior("MeasureContent"),t.addCloseButton(),t.setDimmed(!0),$.hideCrashedDialog=t.hide.bind(t),new s.TargetCrashedScreen.TargetCrashedScreen((()=>{$.hideCrashedDialog=null})).show(t.contentElement),t.show()}targetReloadedAfterCrash(){this.target().runtimeAgent().invoke_runIfWaitingForDebugger(),$.hideCrashedDialog&&($.hideCrashedDialog.call(null),$.hideCrashedDialog=null)}}o.SDKModel.SDKModel.register($,{capabilities:2048,autostart:!0});var G=Object.freeze({__proto__:null,TargetDetachedDialog:$});export{k as ImagePreview,E as JSPresentationUtils,R as Linkifier,_ as Reload,G as TargetDetachedDialog};

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium library

DOM text
is reinterpreted as HTML without escaping meta-characters.
Saadnajmi and others added 23 commits November 22, 2024 06:53
Summary:
Scroll views set up with an inverted vertical axis can't support view flattening due to the flattening not taking the axis inversion in consideration while repositioning the views.

This diff disables view flattening on the cells of the virtualized list so that the layout would be correct in inverted scroll views when using Fabric.

The change is not being applied to ScrollView directly because we can safely assume that vertical axis inversion will only be enabled on VirtualizedList/FlatList.

Test Plan:
Run Zeratul with Fabric and check that the vertical order of grouped bubble messages is correct.

| Before | After |
|--|
|  {F1136386200}  |  {F1136386364}  |

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D50846483

Tasks: T167539420
…ents of VirtualizedList

Summary:
View flattening was already disabled in the cell renderer used by the Virtualized List in this diff D50846483

This diff disables view flattening in the header, footer, empty and spacer cells to fix the layout being broken because of the vertical axis flipping used by the reverse order virtualized list.

Test Plan:
Run Zeratul with Fabric enabled and scroll to the top of a message thread to show the participants summary header.

| Before | After |
|--|
|  {F1145726580}  |  {F1145726618}  |

Reviewers: shawndempsey, chpurrer, #rn-desktop

Reviewed By: chpurrer

Differential Revision: https://phabricator.intern.facebook.com/D51182545

Tasks: T167539420
…yout manager

Summary: To render text using an NSTextView, we need to gain access to a fully configured NSTextStorage to configure the text view to render the text with the right configuration.

Test Plan: Tested later in this stack.

Reviewers: shawndempsey, chpurrer, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D49465173

Tasks: T163838519
Summary: Use an NSTextView to render the text in RCTParagraphComponentView so that we would get UX interactions specific to desktop for free (e.g. text selection)

Test Plan:
- Run Zeratul with Fabric enabled
- Check that text is being rendered correctly with the right size and positioning.

{F1097505779}

Reviewers: shawndempsey, chpurrer, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D49465175

Tasks: T163838519
…hit testing

Summary:
Native views use the AppKit api for hit testing which requires the point to be in the superview coordinate system.

This diff updates the hit testing in `RCTViewComponentView` to conditionally converts the point to the target view coordinate system only if the tested view is a react view.

Test Plan:
Run Zeratul with Fabric and select text inside message bubbles. The scroll view being a native view, the hit testing does not require a point conversion. With this change, the text selection works as expected.

| Before | After |
|--|
|  https://pxl.cl/3Mlpb  |  https://pxl.cl/3MllN  |

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D51129375

Tags: uikit-diff
Summary:
**Context**

- Port Paper TextInput api's to Fabric

https://www.internalfb.com/code/fbsource/[dab91113a70a2f967fa2996f4aca0f49a58aea17]/third-party/microsoft-fork-of-react-native/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m?lines=440-444

**Change**

- Automatic spelling correction works on Fabric TextInput

Test Plan:
**Enable "Correct Spelling Automatically"**
|https://pxl.cl/3MFjJ| https://pxl.cl/3MFx6|

 {F1146645411}

Reviewers: chpurrer, lefever, #rn-desktop

Reviewed By: chpurrer

Differential Revision: https://phabricator.intern.facebook.com/D51158136
Summary:
**Context**

- Port Paper TextInput api's to Fabric

https://www.internalfb.com/code/fbsource/[25297dddce1b]/third-party/microsoft-fork-of-react-native/react-native-macos/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm?lines=500-505

**Change**

- Automatic spell checking works on Fabric TextInput

Test Plan:
**Enable "Check Spelling While Typing"**

https://pxl.cl/3MG01

Reviewers: chpurrer, lefever, #rn-desktop

Reviewed By: chpurrer

Differential Revision: https://phabricator.intern.facebook.com/D51177294
Summary:
**Context**

- Port Paper TextInput api's to Fabric

https://www.internalfb.com/code/fbsource/[25297dddce1b]/third-party/microsoft-fork-of-react-native/react-native-macos/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm?lines=507-512

**Change**

- Automatic grammar checking works on Fabric TextInput

Test Plan:
Enable "Check Grammar With Spelling"

https://pxl.cl/3MWj6

{F1146663064}

Reviewers: chpurrer, lefever, #rn-desktop

Reviewed By: chpurrer

Differential Revision: https://phabricator.intern.facebook.com/D51179163
Summary: `BOOL` being a char type, when building with our current BUCK config we need to static cast it to `bool` in Obj-C++ files when assigning those to a `bool`.

Test Plan:
Build Zeratul with BUCK.

```
BUILDING: FINISHED IN 5m 13.7s (100%) 11302/11302 JOBS, 6/11302 UPDATED

BUILD SUCCEEDED
```

Reviewers: shawndempsey

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D51258122
* chore: set up proper publishing pipeline

* simplify configuration and added docs

* more docs

* add TODO for nightlies

* typos

* also verify ADO pipeline

* refactor checks

* docs

---------

Co-authored-by: Saad Najmi <sanajmi@microsoft.com>
Co-authored-by: microsoft-github-policy-service[bot] <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com>
On CI, checkouts start by creating a new Git repo, then adding a remote
and performing a checkout to a specific commit. This means that we're
usually left in a headless state. Switching to a blobless clone should
allow us to access full Git history without the cost of a full clone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.