@tstdl/base 0.84.0 → 0.84.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/browser-controller.d.ts +2 -8
- package/browser/browser-controller.js +1 -16
- package/browser/browser.service.d.ts +2 -2
- package/browser/browser.service.js +3 -3
- package/browser/element-controller.d.ts +37 -0
- package/browser/element-controller.js +91 -0
- package/browser/index.d.ts +2 -0
- package/browser/index.js +2 -0
- package/browser/page-controller.d.ts +18 -36
- package/browser/page-controller.js +37 -70
- package/browser/types.d.ts +10 -0
- package/browser/types.js +16 -0
- package/browser/utils.d.ts +3 -1
- package/browser/utils.js +11 -0
- package/examples/browser/basic.js +4 -3
- package/http/client/adapters/undici-http-client.adapter.js +1 -1
- package/package.json +5 -3
- package/pdf/pdf.service.js +9 -2
|
@@ -3,10 +3,9 @@ import type { Injectable } from '../container/interfaces.js';
|
|
|
3
3
|
import { resolveArgumentType } from '../container/interfaces.js';
|
|
4
4
|
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
5
5
|
import { disposeAsync } from '../disposable/disposable.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { BrowserContextState, NewPageOptions } from './browser-context-controller.js';
|
|
7
7
|
import { BrowserContextController } from './browser-context-controller.js';
|
|
8
8
|
import type { NewBrowserOptions } from './browser.service.js';
|
|
9
|
-
import type { PageController } from './page-controller.js';
|
|
10
9
|
export type BrowserControllerOptions = {
|
|
11
10
|
defaultNewContextOptions?: NewBrowserContextOptions;
|
|
12
11
|
};
|
|
@@ -14,7 +13,7 @@ export type NewBrowserContextOptions = {
|
|
|
14
13
|
state?: BrowserContextState;
|
|
15
14
|
locale?: string;
|
|
16
15
|
extraHttpHeaders?: Record<string, string>;
|
|
17
|
-
|
|
16
|
+
defaultNewPageOptions?: NewPageOptions;
|
|
18
17
|
viewport?: {
|
|
19
18
|
width: number;
|
|
20
19
|
height: number;
|
|
@@ -35,11 +34,6 @@ export declare class BrowserController implements AsyncDisposable, Injectable<Br
|
|
|
35
34
|
constructor(browser: Browser, options?: BrowserControllerOptions);
|
|
36
35
|
[disposeAsync](): Promise<void>;
|
|
37
36
|
newContext(options?: NewBrowserContextOptions): Promise<BrowserContextController>;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new context and a new page. Context is automatically closed on page close.
|
|
40
|
-
* Only use for isolated or "use once" scenarios, otherwise all the contexts are more expensive than using a single context.
|
|
41
|
-
*/
|
|
42
|
-
newPage(options?: NewBrowserContextOptions & NewPageOptions): Promise<PageController>;
|
|
43
37
|
close(): Promise<void>;
|
|
44
38
|
waitForClose(): Promise<void>;
|
|
45
39
|
}
|
|
@@ -61,22 +61,7 @@ let BrowserController = class BrowserController2 {
|
|
|
61
61
|
proxy: mergedOptions.proxy,
|
|
62
62
|
extraHTTPHeaders: mergedOptions.extraHttpHeaders
|
|
63
63
|
});
|
|
64
|
-
return new import_browser_context_controller.BrowserContextController(context, mergedOptions
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Creates a new context and a new page. Context is automatically closed on page close.
|
|
68
|
-
* Only use for isolated or "use once" scenarios, otherwise all the contexts are more expensive than using a single context.
|
|
69
|
-
*/
|
|
70
|
-
async newPage(options) {
|
|
71
|
-
const context = await this.newContext(options);
|
|
72
|
-
try {
|
|
73
|
-
const page = await context.newPage(options);
|
|
74
|
-
page.ownedContext = context;
|
|
75
|
-
return page;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
await context.close();
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
64
|
+
return new import_browser_context_controller.BrowserContextController(context, mergedOptions);
|
|
80
65
|
}
|
|
81
66
|
async close() {
|
|
82
67
|
if (this.browser.isConnected()) {
|
|
@@ -3,7 +3,7 @@ import { afterResolve, resolveArgumentType } from '../container/interfaces.js';
|
|
|
3
3
|
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
4
4
|
import { disposeAsync } from '../disposable/disposable.js';
|
|
5
5
|
import { BrowserContextController } from './browser-context-controller.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { NewBrowserContextOptions } from './browser-controller.js';
|
|
7
7
|
import { BrowserController } from './browser-controller.js';
|
|
8
8
|
export declare class BrowserServiceOptions {
|
|
9
9
|
defaultNewBrowserOptions?: NewBrowserOptions;
|
|
@@ -18,7 +18,7 @@ export type NewBrowserOptions = {
|
|
|
18
18
|
};
|
|
19
19
|
/** @deprecated should be avoided */
|
|
20
20
|
browserArguments?: string[];
|
|
21
|
-
|
|
21
|
+
defaultNewContextOptions?: NewBrowserContextOptions;
|
|
22
22
|
};
|
|
23
23
|
export declare class BrowserService implements AsyncDisposable, Injectable<BrowserServiceArgument> {
|
|
24
24
|
private readonly browsers;
|
|
@@ -72,11 +72,11 @@ let BrowserService = class BrowserService2 {
|
|
|
72
72
|
const browser = await (0, import_utils.getBrowserType)(mergedOptions.browser).launch(launchOptions);
|
|
73
73
|
this.browsers.add(browser);
|
|
74
74
|
browser.once("disconnected", () => this.browsers.delete(browser));
|
|
75
|
-
return new import_browser_controller.BrowserController(browser, mergedOptions.
|
|
75
|
+
return new import_browser_controller.BrowserController(browser, { defaultNewContextOptions: mergedOptions.defaultNewContextOptions });
|
|
76
76
|
}
|
|
77
77
|
async newPersistentContext(dataDirectory, browserOptions = {}, contextOptions = {}) {
|
|
78
78
|
const mergedBrowserOptions = { ...this.options?.defaultNewBrowserOptions, ...browserOptions };
|
|
79
|
-
const mergedContextOptions = (0, import_utils.mergeNewBrowserContextOptions)(this.options?.defaultNewBrowserOptions?.
|
|
79
|
+
const mergedContextOptions = (0, import_utils.mergeNewBrowserContextOptions)(this.options?.defaultNewBrowserOptions?.defaultNewContextOptions, browserOptions.defaultNewContextOptions, contextOptions);
|
|
80
80
|
const launchOptions = (0, import_utils.getLaunchOptions)(mergedBrowserOptions);
|
|
81
81
|
const context = await (0, import_utils.getBrowserType)(mergedBrowserOptions.browser).launchPersistentContext(dataDirectory, {
|
|
82
82
|
...launchOptions,
|
|
@@ -87,7 +87,7 @@ let BrowserService = class BrowserService2 {
|
|
|
87
87
|
});
|
|
88
88
|
this.persistentBrowserContexts.add(context);
|
|
89
89
|
context.once("close", () => this.persistentBrowserContexts.delete(context));
|
|
90
|
-
return new import_browser_context_controller.BrowserContextController(context, mergedBrowserOptions.
|
|
90
|
+
return new import_browser_context_controller.BrowserContextController(context, mergedBrowserOptions.defaultNewContextOptions);
|
|
91
91
|
}
|
|
92
92
|
async dispose() {
|
|
93
93
|
for (const browser of this.browsers) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Merge, NonUndefinable, TypedOmit } from '../types.js';
|
|
2
|
+
import type { ValueOrProvider } from '../utils/value-or-provider.js';
|
|
3
|
+
import type { ElementHandle, Locator } from 'playwright';
|
|
4
|
+
import { PageController } from './page-controller.js';
|
|
5
|
+
export type Delay = ValueOrProvider<number>;
|
|
6
|
+
export type ActionDelayOptions = {
|
|
7
|
+
actionDelay?: Delay;
|
|
8
|
+
};
|
|
9
|
+
export type TypeDelayOptions = {
|
|
10
|
+
typeDelay?: Delay;
|
|
11
|
+
};
|
|
12
|
+
export type ClickDelayOptions = {
|
|
13
|
+
clickDelay?: Delay;
|
|
14
|
+
};
|
|
15
|
+
export type ElementControllerOptions = {
|
|
16
|
+
actionDelay?: Delay;
|
|
17
|
+
typeDelay?: Delay;
|
|
18
|
+
};
|
|
19
|
+
type LocatorOptions<K extends keyof Locator, I extends keyof Parameters<Locator[K]>> = NonUndefinable<Parameters<Locator[K]>[I]>;
|
|
20
|
+
export declare class ElementController {
|
|
21
|
+
readonly locatorOrHandle: Locator | ElementHandle;
|
|
22
|
+
readonly pageController: PageController;
|
|
23
|
+
readonly options: ElementControllerOptions;
|
|
24
|
+
constructor(locatorOrHandle: Locator | ElementHandle, pageController: PageController, options?: ElementControllerOptions);
|
|
25
|
+
waitFor(options?: Parameters<Locator['waitFor']>[0]): Promise<void>;
|
|
26
|
+
fill(text: string, options?: Merge<LocatorOptions<'fill', 1>, ActionDelayOptions>): Promise<void>;
|
|
27
|
+
type(text: string, options?: Merge<TypedOmit<LocatorOptions<'type', 1>, 'delay'>, ActionDelayOptions & TypeDelayOptions>): Promise<void>;
|
|
28
|
+
selectOption(value: string | string[], options?: Merge<LocatorOptions<'selectOption', 1>, ActionDelayOptions>): Promise<void>;
|
|
29
|
+
click(options?: Merge<TypedOmit<LocatorOptions<'click', 0>, 'delay'>, ActionDelayOptions & ClickDelayOptions>): Promise<void>;
|
|
30
|
+
getValue(options?: LocatorOptions<'inputValue', 0>): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Get PageController for element. Element must be a frame.
|
|
33
|
+
*/
|
|
34
|
+
getPage(options?: LocatorOptions<'elementHandle', 0>): Promise<PageController>;
|
|
35
|
+
private prepareAction;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var element_controller_exports = {};
|
|
20
|
+
__export(element_controller_exports, {
|
|
21
|
+
ElementController: () => ElementController
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(element_controller_exports);
|
|
24
|
+
var import_timing = require("../utils/timing.js");
|
|
25
|
+
var import_type_guards = require("../utils/type-guards.js");
|
|
26
|
+
var import_value_or_provider = require("../utils/value-or-provider.js");
|
|
27
|
+
var import_page_controller = require("./page-controller.js");
|
|
28
|
+
var import_utils = require("./utils.js");
|
|
29
|
+
class ElementController {
|
|
30
|
+
locatorOrHandle;
|
|
31
|
+
pageController;
|
|
32
|
+
options;
|
|
33
|
+
constructor(locatorOrHandle, pageController, options = {}) {
|
|
34
|
+
this.locatorOrHandle = locatorOrHandle;
|
|
35
|
+
this.pageController = pageController;
|
|
36
|
+
this.options = options;
|
|
37
|
+
}
|
|
38
|
+
async waitFor(options) {
|
|
39
|
+
return this.locatorOrHandle.waitFor(options);
|
|
40
|
+
}
|
|
41
|
+
async fill(text, options) {
|
|
42
|
+
await this.prepareAction(options);
|
|
43
|
+
await this.locatorOrHandle.fill(text, options);
|
|
44
|
+
}
|
|
45
|
+
async type(text, options) {
|
|
46
|
+
await this.prepareAction(options);
|
|
47
|
+
if ((0, import_type_guards.isUndefined)(this.options.typeDelay)) {
|
|
48
|
+
await this.locatorOrHandle.type(text, options);
|
|
49
|
+
} else {
|
|
50
|
+
for (const char of text) {
|
|
51
|
+
await this.locatorOrHandle.type(char, options);
|
|
52
|
+
await delay(options?.typeDelay ?? this.options.typeDelay);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async selectOption(value, options) {
|
|
57
|
+
await this.prepareAction(options);
|
|
58
|
+
await this.locatorOrHandle.selectOption(value, options);
|
|
59
|
+
}
|
|
60
|
+
async click(options) {
|
|
61
|
+
await this.prepareAction(options);
|
|
62
|
+
await this.locatorOrHandle.click({
|
|
63
|
+
...options,
|
|
64
|
+
delay: (0, import_value_or_provider.resolveValueOrProvider)(options?.clickDelay)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async getValue(options) {
|
|
68
|
+
return this.locatorOrHandle.inputValue(options);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get PageController for element. Element must be a frame.
|
|
72
|
+
*/
|
|
73
|
+
async getPage(options) {
|
|
74
|
+
const handle = (0, import_utils.isLocator)(this.locatorOrHandle) ? await this.locatorOrHandle.elementHandle(options) : this.locatorOrHandle;
|
|
75
|
+
if ((0, import_type_guards.isNull)(handle)) {
|
|
76
|
+
throw new Error("Could not get element handle.");
|
|
77
|
+
}
|
|
78
|
+
const frame = await this.locatorOrHandle.contentFrame();
|
|
79
|
+
(0, import_type_guards.assertNotNull)(frame, "Could not get content frame for element handle.");
|
|
80
|
+
return new import_page_controller.PageController(frame.page(), this.pageController.options);
|
|
81
|
+
}
|
|
82
|
+
async prepareAction(options) {
|
|
83
|
+
await delay(options?.actionDelay ?? this.options.actionDelay);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function delay(milliseconds) {
|
|
87
|
+
if ((0, import_type_guards.isUndefined)(milliseconds)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await (0, import_timing.timeout)((0, import_value_or_provider.resolveValueOrProvider)(milliseconds));
|
|
91
|
+
}
|
package/browser/index.d.ts
CHANGED
package/browser/index.js
CHANGED
|
@@ -18,4 +18,6 @@ module.exports = __toCommonJS(browser_exports);
|
|
|
18
18
|
__reExport(browser_exports, require("./browser-context-controller.js"), module.exports);
|
|
19
19
|
__reExport(browser_exports, require("./browser-controller.js"), module.exports);
|
|
20
20
|
__reExport(browser_exports, require("./browser.service.js"), module.exports);
|
|
21
|
+
__reExport(browser_exports, require("./element-controller.js"), module.exports);
|
|
21
22
|
__reExport(browser_exports, require("./page-controller.js"), module.exports);
|
|
23
|
+
__reExport(browser_exports, require("./types.js"), module.exports);
|
|
@@ -1,54 +1,36 @@
|
|
|
1
1
|
import type { Page } from 'playwright';
|
|
2
2
|
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
3
3
|
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { NonUndefinable, SimplifyObject } from '../types.js';
|
|
5
|
+
import type { Delay } from './element-controller.js';
|
|
6
|
+
import { ElementController } from './element-controller.js';
|
|
5
7
|
import type { PdfRenderOptions } from './pdf-options.js';
|
|
6
|
-
|
|
7
|
-
export type DelayProvider = () => number;
|
|
8
|
+
import type { Abortable } from './types.js';
|
|
8
9
|
export type PageControllerOptions = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
export type WaitOptions = {
|
|
13
|
-
timeout?: number;
|
|
14
|
-
};
|
|
15
|
-
export type LoadState = 'load' | 'domcontentloaded' | 'networkidle';
|
|
16
|
-
export type WaitForStateOptions = {
|
|
17
|
-
waitUntil: LoadState;
|
|
18
|
-
};
|
|
19
|
-
export type DelayOptions = {
|
|
20
|
-
delay?: Delay;
|
|
21
|
-
};
|
|
22
|
-
export type Abortable = {
|
|
23
|
-
abort?: AbortSignal;
|
|
24
|
-
};
|
|
25
|
-
/** @deprecated for internal use only */
|
|
26
|
-
export type PageControllerInternal = {
|
|
27
|
-
ownedContext?: BrowserContextController;
|
|
10
|
+
defaultActionDelay?: Delay;
|
|
11
|
+
defaultTypeDelay?: Delay;
|
|
28
12
|
};
|
|
29
13
|
export declare class PageController implements AsyncDisposable {
|
|
30
|
-
private readonly
|
|
14
|
+
private readonly elementControllerOptions;
|
|
31
15
|
/** @deprecated should be avoided */
|
|
32
16
|
readonly page: Page;
|
|
33
17
|
readonly options: PageControllerOptions;
|
|
34
18
|
constructor(page: Page, options?: PageControllerOptions);
|
|
35
19
|
[disposeAsync](): Promise<void>;
|
|
36
20
|
close(): Promise<void>;
|
|
37
|
-
setContent(
|
|
21
|
+
setContent(...args: Parameters<Page['setContent']>): Promise<void>;
|
|
38
22
|
setExtraHttpHeaders(headers: Record<string, string>): Promise<void>;
|
|
39
|
-
navigate(
|
|
23
|
+
navigate(...args: Parameters<Page['goto']>): Promise<void>;
|
|
40
24
|
waitForClose(): Promise<void>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
waitForElement(selector: string, options?: WaitOptions): Promise<void>;
|
|
25
|
+
waitForLoadState(...args: Parameters<Page['waitForLoadState']>): Promise<void>;
|
|
26
|
+
waitForUrl(...args: Parameters<Page['waitForURL']>): Promise<void>;
|
|
27
|
+
getBySelector(selector: string, options?: SimplifyObject<Pick<NonUndefinable<Parameters<Page['locator']>[1]>, 'hasText' | 'hasNotText'>>): ElementController;
|
|
28
|
+
getByRole(role: Parameters<Page['getByRole']>[0], options?: Parameters<Page['getByRole']>[1]): ElementController;
|
|
29
|
+
getByLabel(text: Parameters<Page['getByLabel']>[0], options?: Parameters<Page['getByLabel']>[1]): ElementController;
|
|
30
|
+
getByAltText(text: Parameters<Page['getByAltText']>[0], options?: Parameters<Page['getByAltText']>[1]): ElementController;
|
|
31
|
+
getByPlaceholder(text: Parameters<Page['getByPlaceholder']>[0], options?: Parameters<Page['getByPlaceholder']>[1]): ElementController;
|
|
32
|
+
getByText(text: Parameters<Page['getByText']>[0], options?: Parameters<Page['getByText']>[1]): ElementController;
|
|
33
|
+
getByTitle(text: Parameters<Page['getByTitle']>[0], options?: Parameters<Page['getByTitle']>[1]): ElementController;
|
|
51
34
|
renderPdf(options?: PdfRenderOptions & Abortable): Promise<Uint8Array>;
|
|
52
35
|
renderPdfStream(options?: PdfRenderOptions & Abortable): ReadableStream<Uint8Array>;
|
|
53
|
-
private prepareAction;
|
|
54
36
|
}
|
|
@@ -26,33 +26,31 @@ var import_readable_stream_from_promise = require("../utils/stream/readable-stre
|
|
|
26
26
|
var import_timing = require("../utils/timing.js");
|
|
27
27
|
var import_type_guards = require("../utils/type-guards.js");
|
|
28
28
|
var import_units = require("../utils/units.js");
|
|
29
|
+
var import_element_controller = require("./element-controller.js");
|
|
29
30
|
class PageController {
|
|
30
|
-
|
|
31
|
+
elementControllerOptions;
|
|
31
32
|
/** @deprecated should be avoided */
|
|
32
33
|
page;
|
|
33
34
|
options;
|
|
34
35
|
constructor(page, options = {}) {
|
|
35
36
|
this.page = page;
|
|
36
37
|
this.options = options;
|
|
38
|
+
this.elementControllerOptions = { actionDelay: this.options.defaultActionDelay, typeDelay: this.options.defaultTypeDelay };
|
|
37
39
|
}
|
|
38
40
|
async [import_disposable.disposeAsync]() {
|
|
39
41
|
await this.close();
|
|
40
42
|
}
|
|
41
43
|
async close() {
|
|
42
|
-
|
|
43
|
-
await this.ownedContext.close();
|
|
44
|
-
} else {
|
|
45
|
-
await this.page.close();
|
|
46
|
-
}
|
|
44
|
+
await this.page.close();
|
|
47
45
|
}
|
|
48
|
-
async setContent(
|
|
49
|
-
await this.page.setContent(
|
|
46
|
+
async setContent(...args) {
|
|
47
|
+
await this.page.setContent(...args);
|
|
50
48
|
}
|
|
51
49
|
async setExtraHttpHeaders(headers) {
|
|
52
50
|
await this.page.setExtraHTTPHeaders(headers);
|
|
53
51
|
}
|
|
54
|
-
async navigate(
|
|
55
|
-
await this.page.goto(
|
|
52
|
+
async navigate(...args) {
|
|
53
|
+
await this.page.goto(...args);
|
|
56
54
|
}
|
|
57
55
|
async waitForClose() {
|
|
58
56
|
return new Promise((resolve) => {
|
|
@@ -63,56 +61,39 @@ class PageController {
|
|
|
63
61
|
this.page.once("close", () => resolve());
|
|
64
62
|
});
|
|
65
63
|
}
|
|
66
|
-
async
|
|
67
|
-
await this.page.waitForLoadState(
|
|
68
|
-
}
|
|
69
|
-
async
|
|
70
|
-
await this.page.
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
return new PageController(frame.page());
|
|
80
|
-
}
|
|
81
|
-
async fill(selector, text, options) {
|
|
82
|
-
await this.prepareAction();
|
|
83
|
-
const locator = this.page.locator(selector);
|
|
84
|
-
await locator.fill(text, { timeout: options?.timeout });
|
|
85
|
-
}
|
|
86
|
-
async type(selector, text, options) {
|
|
87
|
-
await this.prepareAction();
|
|
88
|
-
const locator = this.page.locator(selector);
|
|
89
|
-
await locator.focus({ timeout: options?.timeout });
|
|
90
|
-
if ((0, import_type_guards.isUndefined)(this.options.typeDelay)) {
|
|
91
|
-
await locator.type(text, { timeout: options?.timeout });
|
|
92
|
-
} else {
|
|
93
|
-
for (const char of text) {
|
|
94
|
-
await locator.type(char, { timeout: options?.timeout });
|
|
95
|
-
await delay(options?.delay ?? this.options.typeDelay);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
64
|
+
async waitForLoadState(...args) {
|
|
65
|
+
await this.page.waitForLoadState(...args);
|
|
66
|
+
}
|
|
67
|
+
async waitForUrl(...args) {
|
|
68
|
+
await this.page.waitForURL(...args);
|
|
69
|
+
}
|
|
70
|
+
getBySelector(selector, options) {
|
|
71
|
+
const locator = this.page.locator(selector, options);
|
|
72
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
73
|
+
}
|
|
74
|
+
getByRole(role, options) {
|
|
75
|
+
const locator = this.page.getByRole(role, options);
|
|
76
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
98
77
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
await locator.selectOption(value, { timeout: options?.timeout });
|
|
78
|
+
getByLabel(text, options) {
|
|
79
|
+
const locator = this.page.getByLabel(text, options);
|
|
80
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
103
81
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
await locator.click({ delay: 50, timeout: options?.timeout });
|
|
82
|
+
getByAltText(text, options) {
|
|
83
|
+
const locator = this.page.getByAltText(text, options);
|
|
84
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
108
85
|
}
|
|
109
|
-
|
|
110
|
-
const locator = this.page.
|
|
111
|
-
return
|
|
86
|
+
getByPlaceholder(text, options) {
|
|
87
|
+
const locator = this.page.getByPlaceholder(text, options);
|
|
88
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
112
89
|
}
|
|
113
|
-
|
|
114
|
-
const locator = this.page.
|
|
115
|
-
return
|
|
90
|
+
getByText(text, options) {
|
|
91
|
+
const locator = this.page.getByText(text, options);
|
|
92
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
93
|
+
}
|
|
94
|
+
getByTitle(text, options) {
|
|
95
|
+
const locator = this.page.getByTitle(text, options);
|
|
96
|
+
return new import_element_controller.ElementController(locator, this, this.elementControllerOptions);
|
|
116
97
|
}
|
|
117
98
|
async renderPdf(options = {}) {
|
|
118
99
|
const createPdfOptions = convertPdfOptions(options);
|
|
@@ -129,20 +110,6 @@ class PageController {
|
|
|
129
110
|
});
|
|
130
111
|
});
|
|
131
112
|
}
|
|
132
|
-
async prepareAction() {
|
|
133
|
-
await delay(this.options.actionDelay);
|
|
134
|
-
await this.waitForNetworkIdle();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async function delay(milliseconds) {
|
|
138
|
-
if ((0, import_type_guards.isUndefined)(milliseconds)) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if ((0, import_type_guards.isNumber)(milliseconds)) {
|
|
142
|
-
await (0, import_timing.timeout)(milliseconds);
|
|
143
|
-
} else {
|
|
144
|
-
await (0, import_timing.timeout)(milliseconds());
|
|
145
|
-
}
|
|
146
113
|
}
|
|
147
114
|
function convertPdfOptions(options) {
|
|
148
115
|
const margin = (0, import_type_guards.isUndefined)(options.margin) ? void 0 : (0, import_type_guards.isObject)(options.margin) ? options.margin : {
|
package/browser/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/browser/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { BrowserType, LaunchOptions } from 'playwright';
|
|
1
|
+
import type { BrowserType, ElementHandle, LaunchOptions, Locator } from 'playwright';
|
|
2
2
|
import type { NewBrowserContextOptions } from './browser-controller.js';
|
|
3
3
|
import type { NewBrowserOptions } from './browser.service.js';
|
|
4
4
|
export declare function getLaunchOptions(options: NewBrowserOptions): LaunchOptions;
|
|
5
5
|
export declare function mergeNewBrowserContextOptions(a: NewBrowserContextOptions | undefined, b?: NewBrowserContextOptions, c?: NewBrowserContextOptions): NewBrowserContextOptions;
|
|
6
6
|
export declare function getBrowserType(type: string | undefined): BrowserType;
|
|
7
|
+
export declare function isLocator(value: Locator | ElementHandle): value is Locator;
|
|
8
|
+
export declare function isElementHandle(value: Locator | ElementHandle): value is ElementHandle;
|
package/browser/utils.js
CHANGED
|
@@ -20,11 +20,14 @@ var utils_exports = {};
|
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
getBrowserType: () => getBrowserType,
|
|
22
22
|
getLaunchOptions: () => getLaunchOptions,
|
|
23
|
+
isElementHandle: () => isElementHandle,
|
|
24
|
+
isLocator: () => isLocator,
|
|
23
25
|
mergeNewBrowserContextOptions: () => mergeNewBrowserContextOptions
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(utils_exports);
|
|
26
28
|
var import_not_supported_error = require("../error/not-supported.error.js");
|
|
27
29
|
var import_object = require("../utils/object/object.js");
|
|
30
|
+
var import_type_guards = require("../utils/type-guards.js");
|
|
28
31
|
var import_playwright = require("playwright");
|
|
29
32
|
function getLaunchOptions(options) {
|
|
30
33
|
const { windowSize, browserArguments, headless } = options;
|
|
@@ -58,3 +61,11 @@ function getBrowserType(type) {
|
|
|
58
61
|
}
|
|
59
62
|
return browserType;
|
|
60
63
|
}
|
|
64
|
+
const exclusiveLocatorKey = "locator";
|
|
65
|
+
function isLocator(value) {
|
|
66
|
+
return (0, import_type_guards.isFunction)(value[exclusiveLocatorKey]);
|
|
67
|
+
}
|
|
68
|
+
const exclusiveElementHandleKey = "$";
|
|
69
|
+
function isElementHandle(value) {
|
|
70
|
+
return (0, import_type_guards.isFunction)(value[exclusiveElementHandleKey]);
|
|
71
|
+
}
|
|
@@ -7,13 +7,14 @@ var import_timing = require("../../utils/timing.js");
|
|
|
7
7
|
async function main() {
|
|
8
8
|
const browserService = await import_container.container.resolveAsync(import_browser_service.BrowserService);
|
|
9
9
|
const browser = await browserService.newBrowser({ headless: false });
|
|
10
|
-
const
|
|
10
|
+
const context = await browser.newContext();
|
|
11
|
+
const page = await context.newPage();
|
|
11
12
|
await page.navigate("https://google.com");
|
|
12
|
-
await page.
|
|
13
|
+
await page.getBySelector("//div[text() = 'Alle ablehnen']").click();
|
|
13
14
|
await (0, import_timing.timeout)(1e3);
|
|
14
15
|
const pdf = await page.renderPdf();
|
|
15
16
|
(0, import_node_fs.writeFileSync)("/tmp/pdf.pdf", pdf);
|
|
16
17
|
await page.navigate("file:///tmp/pdf.pdf");
|
|
17
|
-
await
|
|
18
|
+
await page.waitForClose();
|
|
18
19
|
}
|
|
19
20
|
import_application.Application.run(main);
|
|
@@ -82,7 +82,7 @@ let UndiciHttpClientAdapter = class UndiciHttpClientAdapter2 extends import_http
|
|
|
82
82
|
try {
|
|
83
83
|
const response = await (0, import_undici.request)(httpClientRequest.url, {
|
|
84
84
|
method: httpClientRequest.method,
|
|
85
|
-
signal: httpClientRequest.abortToken.asAbortSignal,
|
|
85
|
+
signal: httpClientRequest.abortToken.asAbortSignal(),
|
|
86
86
|
headers: httpClientRequest.headers.asNormalizedObject(),
|
|
87
87
|
body,
|
|
88
88
|
headersTimeout: httpClientRequest.timeout,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.84.
|
|
3
|
+
"version": "0.84.2",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc && tsc-alias",
|
|
11
|
-
"build:watch": "
|
|
11
|
+
"build:watch": "concurrently --raw --kill-others npm:tsc:watch npm:tsc-alias:watch",
|
|
12
12
|
"build:production": "rm -rf dist && npm run build && npm run build:production:cjs && npm run build:production:copy-files",
|
|
13
13
|
"build:production:cjs": "esbuild `find dist \\( -name '*.js' -o -name '*.jsx' \\)` --outdir=dist --allow-overwrite --format=cjs",
|
|
14
14
|
"build:production:copy-files": "cp package.json .eslintrc.json tsconfig.server.json dist/ && cp tsconfig.base.json dist/tsconfig.json && sed -i 's/\"type\": \"module\",/\"type\": \"commonjs\",/g' dist/package.json",
|
|
15
15
|
"build:docs": "typedoc",
|
|
16
16
|
"build:docs-watch": "typedoc --watch",
|
|
17
17
|
"lint": "eslint -c .eslintrc.json --ext .ts .",
|
|
18
|
-
"pub": "npm run build:production && rm -vf dist/test* && npm publish dist/"
|
|
18
|
+
"pub": "npm run build:production && rm -vf dist/test* && npm publish dist/",
|
|
19
|
+
"tsc:watch": "tsc --watch",
|
|
20
|
+
"tsc-alias:watch": "tsc-alias --watch"
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"luxon": "^3.3",
|
package/pdf/pdf.service.js
CHANGED
|
@@ -153,10 +153,17 @@ let PdfService = class PdfService2 {
|
|
|
153
153
|
}
|
|
154
154
|
renderStream(handler, options = {}) {
|
|
155
155
|
return (0, import_readable_stream_from_promise.readableStreamFromPromise)(async () => {
|
|
156
|
-
const
|
|
156
|
+
const context = options.browserContext ?? await this.browserController.newContext({ locale: options.locale ?? this.defaultLocale });
|
|
157
|
+
const page = await context.newPage();
|
|
157
158
|
const optionsFromHandler = await handler(page);
|
|
158
159
|
const pdfStream = page.renderPdfStream({ ...optionsFromHandler, ...options });
|
|
159
|
-
const close = async () =>
|
|
160
|
+
const close = async () => {
|
|
161
|
+
if ((0, import_type_guards.isDefined)(options.browserContext)) {
|
|
162
|
+
await page.close();
|
|
163
|
+
} else {
|
|
164
|
+
await context.close();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
160
167
|
return (0, import_finalize_stream.finalizeStream)(pdfStream, {
|
|
161
168
|
beforeDone: close,
|
|
162
169
|
beforeCancel: close,
|