@mablhq/mabl-cli 1.17.6 → 1.18.3

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.
Files changed (55) hide show
  1. package/api/featureSet.js +1 -4
  2. package/api/mablApiClient.js +2 -2
  3. package/browserLauncher/browserLauncherFactory.js +2 -3
  4. package/browserLauncher/playwrightBrowserLauncher/playwrightBrowser.js +3 -0
  5. package/browserLauncher/playwrightBrowserLauncher/playwrightDom.js +1 -11
  6. package/browserLauncher/playwrightBrowserLauncher/playwrightFrame.js +18 -0
  7. package/browserLauncher/runnerType.js +0 -1
  8. package/execution/index.js +1 -1
  9. package/execution/index.js.LICENSE.txt +2 -0
  10. package/index.d.ts +0 -1
  11. package/mablscript/MablAction.js +1 -1
  12. package/mablscript/MablStep.js +21 -3
  13. package/mablscript/actions/AwaitPDFDownloadAction.js +2 -1
  14. package/mablscript/actions/ConditionAction.js +11 -3
  15. package/mablscript/actions/ExtractAction.js +16 -7
  16. package/mablscript/actions/FindAction.js +71 -40
  17. package/mablscript/actions/GenerateRandomStringAction.js +2 -1
  18. package/mablscript/actions/GetUrlAction.js +1 -1
  19. package/mablscript/actions/GetVariableValue.js +2 -2
  20. package/mablscript/diffing/diffingUtil.js +146 -0
  21. package/mablscript/importer.js +20 -2
  22. package/mablscript/steps/AssertStep.js +33 -19
  23. package/mablscript/steps/AssertStepOld.js +38 -20
  24. package/mablscript/steps/AwaitTabStep.js +7 -6
  25. package/mablscript/steps/ClickAndHoldStep.js +1 -1
  26. package/mablscript/steps/DownloadStep.js +3 -2
  27. package/mablscript/steps/EchoStep.js +3 -1
  28. package/mablscript/steps/ElseIfConditionStep.js +5 -2
  29. package/mablscript/steps/EnterTextStep.js +4 -1
  30. package/mablscript/steps/EvaluateFlowStep.js +40 -0
  31. package/mablscript/steps/ReleaseStep.js +2 -1
  32. package/mablscript/steps/RemoveCookieStep.js +2 -3
  33. package/mablscript/steps/SendHttpRequestStep.js +3 -3
  34. package/mablscript/steps/SendKeyStep.js +2 -2
  35. package/mablscript/steps/SetCookieStep.js +2 -4
  36. package/mablscript/steps/SetViewportStep.js +1 -1
  37. package/mablscript/steps/VisitUrlStep.js +2 -1
  38. package/mablscript/steps/WaitStep.js +1 -4
  39. package/{browserLauncher/puppeteerBrowserLauncher/internals.js → mablscript/types/EvaluateFlowStepDescriptor.js} +0 -0
  40. package/mablscript/types/GetCurrentLocationDescriptor.js +4 -3
  41. package/mablscriptFind/index.js +1 -1
  42. package/package.json +3 -3
  43. package/resources/mablFind.js +1 -1
  44. package/resources/pdf-viewer/index.js +1 -1
  45. package/resources/pdf-viewer/libEmbeddedPdfHandler.js +11 -2
  46. package/util/actionabilityUtil.js +1 -24
  47. package/browserLauncher/puppeteerBrowserLauncher/puppeteerBrowser.js +0 -135
  48. package/browserLauncher/puppeteerBrowserLauncher/puppeteerBrowserLauncher.js +0 -45
  49. package/browserLauncher/puppeteerBrowserLauncher/puppeteerElementHandle.js +0 -139
  50. package/browserLauncher/puppeteerBrowserLauncher/puppeteerFrame.js +0 -115
  51. package/browserLauncher/puppeteerBrowserLauncher/puppeteerHttpRequest.js +0 -38
  52. package/browserLauncher/puppeteerBrowserLauncher/puppeteerHttpResponse.js +0 -27
  53. package/browserLauncher/puppeteerBrowserLauncher/puppeteerJsHandle.js +0 -36
  54. package/browserLauncher/puppeteerBrowserLauncher/puppeteerPage.js +0 -335
  55. package/browserLauncher/puppeteerBrowserLauncher/wrappers.js +0 -25
@@ -171,10 +171,19 @@ class EmbeddedPdfHandler {
171
171
  // we're likely in the chrome viewer, so window.location actually has
172
172
  // the right URL
173
173
  pdfUrl = window.location.href;
174
+ } // Firefox does not always get the correct offsetHeight and offsetWidth
175
+ // so if the value returned is 0, then just leave the size to the default size
176
+
177
+
178
+ if (originalPdfElement.offsetHeight && originalPdfElement.offsetWidth) {
179
+ viewerElem.height = originalPdfElement.offsetHeight;
180
+ viewerElem.width = originalPdfElement.offsetWidth;
181
+ } else if (originalPdfElement.height && originalPdfElement.width) {
182
+ // Default to height and width of original if available
183
+ viewerElem.height = originalPdfElement.height;
184
+ viewerElem.width = originalPdfElement.width;
174
185
  }
175
186
 
176
- viewerElem.height = originalPdfElement.offsetHeight;
177
- viewerElem.width = originalPdfElement.offsetWidth;
178
187
  viewerElem.id = '__mabl_pdf_viewer_' + this.idSanitize(this.getPdfFilenameFromUrl(pdfUrl));
179
188
  viewerElem.src = this.getEmbeddedViewerURL(pdfUrl);
180
189
  viewerElem.setAttribute(MABL_PROCESSED_PDF_ATTRIBUTE, 'true');
@@ -23,11 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.maybeAddPopupLogic = exports.attemptPopupDismissal = exports.checkActionabilityAt = exports.checkActionabilityAtWithRetries = exports.checkPopupDismissalOnAction = void 0;
26
+ exports.maybeAddPopupLogic = exports.attemptPopupDismissal = exports.checkActionabilityAt = exports.checkPopupDismissalOnAction = void 0;
27
27
  const fs = __importStar(require("fs"));
28
28
  const resourceUtil_1 = require("./resourceUtil");
29
29
  const messaging_1 = require("../core/messaging/messaging");
30
- const ExecutorUtils_1 = require("../execution/actions/ExecutorUtils");
31
30
  const logUtils_1 = require("./logUtils");
32
31
  const loggingProvider_1 = require("../providers/logging/loggingProvider");
33
32
  const ACTIONABILITY_CHECK_SCRIPT_LOCATION = (0, resourceUtil_1.findResource)('actionabilityCheck.js');
@@ -60,28 +59,6 @@ async function checkPopupDismissalOnAction(elementHandle, action, executionConte
60
59
  }
61
60
  }
62
61
  exports.checkPopupDismissalOnAction = checkPopupDismissalOnAction;
63
- async function checkActionabilityAtWithRetries(elementHandle, executionContext, failIfClickablePointWasNotFound = true) {
64
- var _a, _b, _c, _d;
65
- let actionabilityResult;
66
- try {
67
- actionabilityResult = await (0, ExecutorUtils_1.runWithRetries)(() => checkActionabilityAt(elementHandle, executionContext), 10, [
68
- 'Element not at point',
69
- 'Element not clickable at point',
70
- NO_CLICKABLE_POINT_ERROR,
71
- ], executionContext);
72
- }
73
- catch (error) {
74
- if (failIfClickablePointWasNotFound &&
75
- error.message === NO_CLICKABLE_POINT_ERROR) {
76
- throw new Error(NO_CLICKABLE_POINT_ERROR);
77
- }
78
- (0, logUtils_1.logWebUIAndCliOutput)(`Found element may not be actionable`, loggingProvider_1.LogLevel.Warn, executionContext, {
79
- executionPhase: messaging_1.ExecutionPhase.DURING_ACTION,
80
- });
81
- (0, logUtils_1.logInternal)(`Found element might not be actionable at the expected point (x: ${(_b = (_a = actionabilityResult === null || actionabilityResult === void 0 ? void 0 : actionabilityResult.clickablePoint) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 'Not found'}, y: ${(_d = (_c = actionabilityResult === null || actionabilityResult === void 0 ? void 0 : actionabilityResult.clickablePoint) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : 'Not found'}), performing action anyway`);
82
- }
83
- }
84
- exports.checkActionabilityAtWithRetries = checkActionabilityAtWithRetries;
85
62
  async function checkActionabilityAt(elementHandle, executionContext, recheckOnFail = true) {
86
63
  let point = await elementHandle.clickablePoint();
87
64
  if (point === undefined) {
@@ -1,135 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PuppeteerBrowser = void 0;
7
- const browserLauncher_1 = require("../browserLauncher");
8
- const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
9
- const events_1 = __importDefault(require("events"));
10
- const puppeteerBrowserLauncher_1 = require("./puppeteerBrowserLauncher");
11
- const puppeteerPage_1 = require("./puppeteerPage");
12
- const runnerType_1 = require("../runnerType");
13
- class PuppeteerBrowser extends events_1.default {
14
- constructor(browser, downloadDirectory, credentials, userAgent) {
15
- var _a;
16
- super();
17
- this.browser = browser;
18
- this.downloadDirectory = downloadDirectory;
19
- this.credentials = credentials;
20
- this.userAgent = userAgent;
21
- this.puppeteerPages = new Map();
22
- (_a = this.browser
23
- .process()) === null || _a === void 0 ? void 0 : _a.on('close', () => this.emit(browserLauncher_1.BrowserEvent.BrowserDestroyed));
24
- this.browser.on('targetcreated', async (target) => {
25
- const page = await target.page();
26
- if (page) {
27
- this.emit(browserLauncher_1.BrowserEvent.PageCreated, await this.getOrCreatePage(page));
28
- }
29
- });
30
- this.browser.on("disconnected", () => this.emit(browserLauncher_1.BrowserEvent.Disconnected));
31
- browser._connection.on('Browser.downloadWillBegin', (event) => this.emit(browserLauncher_1.BrowserEvent.DownloadWillBegin, {
32
- guid: event.guid,
33
- suggestedFilename: event.suggestedFilename,
34
- url: event.url,
35
- }));
36
- browser._connection.on('Browser.downloadProgress', (event) => this.emit(browserLauncher_1.BrowserEvent.DownloadProgress, {
37
- guid: event.guid,
38
- totalBytes: event.totalBytes,
39
- receivedBytes: event.receivedBytes,
40
- state: event.state,
41
- }));
42
- }
43
- getRunnerType() {
44
- return runnerType_1.RunnerType.Puppeteer;
45
- }
46
- getDownloadDirectory() {
47
- return this.downloadDirectory;
48
- }
49
- makeCdpCall(method, paramArgs) {
50
- const connection = this.browser._connection;
51
- return connection.send(method, paramArgs);
52
- }
53
- disconnect() {
54
- this.browser.disconnect();
55
- return Promise.resolve();
56
- }
57
- reconnect() {
58
- const webSocketEndpoint = this.wsEndpoint();
59
- if (!webSocketEndpoint) {
60
- throw new Error(`No browser websocket endpoint configured or supplied for connection`);
61
- }
62
- return browserLauncher_1.BrowserLauncherFactory.createRunner(this.getRunnerType()).connect({
63
- defaultDeviceDescriptor: undefined,
64
- browserWSEndpoint: webSocketEndpoint,
65
- }, this.getDownloadDirectory());
66
- }
67
- async newPage() {
68
- return this.getOrCreatePage(await this.browser.newPage());
69
- }
70
- isConnected() {
71
- return this.browser.isConnected();
72
- }
73
- async setDownloadBehavior(downloadDirectory) {
74
- const request = {
75
- behavior: 'allow',
76
- downloadPath: downloadDirectory,
77
- eventsEnabled: true,
78
- };
79
- await this.makeCdpCall('Browser.setDownloadBehavior', request);
80
- }
81
- wsEndpoint() {
82
- return this.browser.wsEndpoint();
83
- }
84
- close() {
85
- return this.browser.close();
86
- }
87
- async pages() {
88
- const pages = await this.browser.pages();
89
- return Promise.all(pages.map((page) => this.getOrCreatePage(page)));
90
- }
91
- async getExtensionBackgroundPage(extensionId) {
92
- const targets = this.browser.targets();
93
- const target = targets.find((target) => target.type() === 'background_page' &&
94
- target.url().includes(extensionId));
95
- if (target) {
96
- const backgroundPage = await target.page();
97
- if (!backgroundPage) {
98
- throw new browserLauncher_1.RunnerError('No background page found');
99
- }
100
- return this.getOrCreatePage(backgroundPage);
101
- }
102
- throw new Error('mabl test initialization failure, unable to locate mabl extension page, please try again');
103
- }
104
- async waitForPage(opener, options) {
105
- try {
106
- const pageTarget = opener.getPuppeteerPage().target();
107
- const newTarget = await this.browser.waitForTarget((target) => target.opener() === pageTarget, (0, puppeteerBrowserLauncher_1.convertWaitForOptions)(options));
108
- return this.getOrCreatePage((await newTarget.page()));
109
- }
110
- catch (e) {
111
- if (e instanceof puppeteer_core_1.default.errors.TimeoutError) {
112
- throw new browserLauncher_1.RUNNER_ERRORS.TimeoutError(e.message);
113
- }
114
- throw new browserLauncher_1.RunnerError(e.message);
115
- }
116
- }
117
- getPuppeteerBrowser() {
118
- return this.browser;
119
- }
120
- onPageClose(page) {
121
- this.puppeteerPages.delete(page.getPageId());
122
- this.emit(browserLauncher_1.BrowserEvent.PageDestroyed, page);
123
- }
124
- async getOrCreatePage(page) {
125
- const pageId = page.target()._targetId;
126
- if (!this.puppeteerPages.has(pageId)) {
127
- const newPage = new puppeteerPage_1.PuppeteerPage(page, this);
128
- this.puppeteerPages.set(pageId, newPage);
129
- }
130
- const puppeteerPage = this.puppeteerPages.get(pageId);
131
- await puppeteerPage.waitForInitialization();
132
- return puppeteerPage;
133
- }
134
- }
135
- exports.PuppeteerBrowser = PuppeteerBrowser;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.convertWaitForOptions = exports.PuppeteerBrowserLauncher = void 0;
7
- const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
8
- const types_1 = require("../types");
9
- const puppeteerBrowser_1 = require("./puppeteerBrowser");
10
- class PuppeteerBrowserLauncher {
11
- async connect(options, currentDownloadPath) {
12
- return new puppeteerBrowser_1.PuppeteerBrowser(await puppeteer_core_1.default.connect({
13
- browserWSEndpoint: options.browserWSEndpoint,
14
- defaultViewport: options.defaultDeviceDescriptor,
15
- }), currentDownloadPath);
16
- }
17
- async launch(options) {
18
- const browser = new puppeteerBrowser_1.PuppeteerBrowser(await puppeteer_core_1.default.launch({
19
- ignoreHTTPSErrors: true,
20
- ...options,
21
- }), options.downloadPath, options.credentials, options.userAgent);
22
- if (options.downloadPath) {
23
- await browser.setDownloadBehavior(options.downloadPath);
24
- }
25
- return browser;
26
- }
27
- }
28
- exports.PuppeteerBrowserLauncher = PuppeteerBrowserLauncher;
29
- function convertWaitForOptions(options) {
30
- return {
31
- timeout: options === null || options === void 0 ? void 0 : options.timeout,
32
- waitUntil: convertWaitUntil(options === null || options === void 0 ? void 0 : options.waitUntil),
33
- };
34
- }
35
- exports.convertWaitForOptions = convertWaitForOptions;
36
- function convertWaitUntil(waitUntil) {
37
- switch (waitUntil) {
38
- case types_1.LifecycleEvent.DomContentLoaded:
39
- return 'domcontentloaded';
40
- case types_1.LifecycleEvent.NetworkIdle:
41
- return 'networkidle2';
42
- default:
43
- return 'load';
44
- }
45
- }
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PuppeteerElementHandle = void 0;
4
- const puppeteerJsHandle_1 = require("./puppeteerJsHandle");
5
- const utils_1 = require("../utils");
6
- const testsUtil_1 = require("../../commands/tests/testsUtil");
7
- const elementHandle_1 = require("../elementHandle");
8
- const pureUtil_1 = require("../../util/pureUtil");
9
- const msBetweenClicks = 100;
10
- class PuppeteerElementHandle extends puppeteerJsHandle_1.PuppeteerJsHandle {
11
- constructor(element, parentPage) {
12
- super(element, parentPage);
13
- this.element = element;
14
- this.parentPage = parentPage;
15
- }
16
- uploadFile(filePath) {
17
- return this.element.uploadFile(filePath);
18
- }
19
- async contentFrame() {
20
- const frame = await this.element.contentFrame();
21
- return (0, utils_1.mapIfNotNull)(frame, (frame) => this.parentPage.getOrCreateFrame(frame));
22
- }
23
- focus() {
24
- return this.element.focus();
25
- }
26
- select(value) {
27
- return this.element.select(value);
28
- }
29
- clickablePoint() {
30
- return this.element._clickablePoint();
31
- }
32
- scrollIntoViewIfNeeded() {
33
- return this.element._scrollIntoViewIfNeeded();
34
- }
35
- hover() {
36
- return this.element.hover();
37
- }
38
- click(options) {
39
- if (options === null || options === void 0 ? void 0 : options.trial) {
40
- return Promise.resolve();
41
- }
42
- return this.element.click(options);
43
- }
44
- async doubleClick(options) {
45
- if (options === null || options === void 0 ? void 0 : options.trial) {
46
- return Promise.resolve();
47
- }
48
- await this.element.click();
49
- await (0, testsUtil_1.sleep)(msBetweenClicks);
50
- return this.element.click({ clickCount: 2 });
51
- }
52
- asElement() {
53
- return (0, utils_1.mapIfNotNull)(this.handle.asElement(), (handle) => new PuppeteerElementHandle(handle, this.parentPage));
54
- }
55
- type(text, options) {
56
- return this.element.type(text, options);
57
- }
58
- async $x(xpathQuery) {
59
- return (await this.element.$x(xpathQuery)).map((element) => new PuppeteerElementHandle(element, this.parentPage));
60
- }
61
- async boundingBox() {
62
- const boundingBox = await this.element.boundingBox();
63
- return (0, utils_1.mapIfNotNull)(boundingBox, (boundingBox) => boundingBox);
64
- }
65
- frame() {
66
- return Promise.resolve((0, utils_1.mapIfNotNull)(this.element.executionContext().frame(), (frame) => this.parentPage.getOrCreateFrame(frame)));
67
- }
68
- press(key) {
69
- return this.element.press(key);
70
- }
71
- getRemoteObjectId() {
72
- return this.element._remoteObject.objectId;
73
- }
74
- async highlight(highlightDurationMillis, highlightPhases) {
75
- await this.enableDom();
76
- await this.enableOverlay();
77
- const nodeInfo = await this.makeCdpCall('DOM.describeNode', {
78
- objectId: this.getRemoteObjectId(),
79
- depth: -1,
80
- pierce: true,
81
- });
82
- const highlightConfig = {
83
- backendNodeId: nodeInfo.node.backendNodeId,
84
- highlightConfig: {
85
- borderColor: (0, elementHandle_1.getHighlightColor)(0),
86
- contentColor: (0, elementHandle_1.getHighlightColor)(1),
87
- colorFormat: 'rgb',
88
- },
89
- };
90
- await this.fadeInOutHighlight(highlightConfig, highlightDurationMillis, highlightPhases);
91
- await this.hideHighlight();
92
- }
93
- async enableDom() {
94
- await this.makeCdpCall('DOM.enable');
95
- }
96
- async enableOverlay() {
97
- await this.makeCdpCall('Overlay.enable');
98
- }
99
- async hideHighlight() {
100
- await this.makeCdpCall('Overlay.hideHighlight');
101
- }
102
- async fadeInOutHighlight(highlightConfig, highlightDurationMillis, highlightPhases) {
103
- var _a;
104
- if (highlightPhases <= 0) {
105
- throw new Error('Highlight phases must be greater than 0');
106
- }
107
- const phaseIntervalMilliseconds = highlightDurationMillis / highlightPhases;
108
- for (let iteration = 0; iteration < highlightPhases; iteration++) {
109
- if (((_a = highlightConfig.highlightConfig.contentColor) === null || _a === void 0 ? void 0 : _a.a) !== undefined) {
110
- const x = iteration / highlightPhases;
111
- highlightConfig.highlightConfig.contentColor.a =
112
- x * (1 - x) * 4 * elementHandle_1.MAX_HIGHLIGHT_OPACITY;
113
- }
114
- await this.makeCdpCall('Overlay.highlightNode', highlightConfig);
115
- await (0, testsUtil_1.sleep)(phaseIntervalMilliseconds);
116
- }
117
- }
118
- getCdpClient() {
119
- return this.element._client;
120
- }
121
- makeCdpCall(method, paramArgs) {
122
- return this.getCdpClient().send(method, paramArgs);
123
- }
124
- getValue() {
125
- return this.element.evaluate((el) => el.value);
126
- }
127
- async getInnerText() {
128
- const result = await this.element.evaluate((el) => el.innerText);
129
- return (0, pureUtil_1.isNullish)(result) ? undefined : result;
130
- }
131
- getTagName() {
132
- return this.element.evaluate((el) => el.tagName.toLowerCase());
133
- }
134
- async getAttribute(attributeName) {
135
- const result = await this.element.evaluate((el, attributeName) => el.getAttribute(attributeName), attributeName);
136
- return (0, pureUtil_1.isNullish)(result) ? undefined : result;
137
- }
138
- }
139
- exports.PuppeteerElementHandle = PuppeteerElementHandle;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PuppeteerFrame = void 0;
7
- const browserLauncher_1 = require("../browserLauncher");
8
- const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
9
- const loggingProvider_1 = require("../../providers/logging/loggingProvider");
10
- const puppeteerBrowserLauncher_1 = require("./puppeteerBrowserLauncher");
11
- const utils_1 = require("../utils");
12
- const puppeteerHttpResponse_1 = require("./puppeteerHttpResponse");
13
- const puppeteerElementHandle_1 = require("./puppeteerElementHandle");
14
- const puppeteerJsHandle_1 = require("./puppeteerJsHandle");
15
- class PuppeteerFrame extends browserLauncher_1.Frame {
16
- constructor(frame, parentPage) {
17
- super();
18
- this.frame = frame;
19
- this.parentPage = parentPage;
20
- }
21
- makeCdpCall(method, paramArgs) {
22
- const client = this.frame.executionContext()._client;
23
- return client.send(method, paramArgs);
24
- }
25
- page() {
26
- return this.parentPage;
27
- }
28
- name() {
29
- return this.frame.name();
30
- }
31
- childFrames() {
32
- return this.frame
33
- .childFrames()
34
- .map((frame) => this.parentPage.getOrCreateFrame(frame));
35
- }
36
- async $eval(selector, pageFunction, arg) {
37
- const result = await this.frame.$eval(selector, pageFunction, puppeteerJsHandle_1.PuppeteerJsHandle.unwrapProperties(arg));
38
- return result;
39
- }
40
- async $$eval(selector, pageFunction, arg) {
41
- const result = await this.frame.$$eval(selector, pageFunction, puppeteerJsHandle_1.PuppeteerJsHandle.unwrapProperties(arg));
42
- return result;
43
- }
44
- async $(selector) {
45
- const handle = await this.frame.$(selector);
46
- return (0, utils_1.mapIfNotNull)(handle, (handle) => new puppeteerElementHandle_1.PuppeteerElementHandle(handle, this.parentPage));
47
- }
48
- async $$(selector) {
49
- return (await this.frame.$$(selector)).map((element) => new puppeteerElementHandle_1.PuppeteerElementHandle(element, this.parentPage));
50
- }
51
- async $x(xpathQuery) {
52
- return (await this.frame.$x(xpathQuery)).map((element) => new puppeteerElementHandle_1.PuppeteerElementHandle(element, this.parentPage));
53
- }
54
- id() {
55
- return this.frame._id;
56
- }
57
- url() {
58
- return this.frame.url();
59
- }
60
- title() {
61
- return this.frame.title();
62
- }
63
- async goto(url, options) {
64
- try {
65
- const response = await this.frame.goto(url, (0, puppeteerBrowserLauncher_1.convertWaitForOptions)(options));
66
- return (0, utils_1.mapIfNotNull)(response, (response) => new puppeteerHttpResponse_1.PuppeteerHttpResponse(response, this.parentPage));
67
- }
68
- catch (e) {
69
- if (e instanceof puppeteer_core_1.default.errors.TimeoutError) {
70
- throw new browserLauncher_1.RUNNER_ERRORS.TimeoutError(e.message);
71
- }
72
- throw new browserLauncher_1.RunnerError(e.message);
73
- }
74
- }
75
- parentFrame() {
76
- return (0, utils_1.mapIfNotNull)(this.frame.parentFrame(), (frame) => this.parentPage.getOrCreateFrame(frame));
77
- }
78
- evaluate(pageFunction, arg) {
79
- return this.frame.evaluate(pageFunction, puppeteerJsHandle_1.PuppeteerJsHandle.unwrapProperties(arg));
80
- }
81
- async evaluateCodeInSecondaryWorld(code, arg) {
82
- let result;
83
- if (this.frame._secondaryWorld._hasContext()) {
84
- result = await this.frame._secondaryWorld.evaluate(code, puppeteerJsHandle_1.PuppeteerJsHandle.unwrapProperties(arg));
85
- }
86
- else {
87
- loggingProvider_1.logger.debug('Using primary world to evaluate instead of secondary world');
88
- result = await this.evaluate(code, arg);
89
- }
90
- return result;
91
- }
92
- async evaluateHandleInSecondaryWorld(code, arg) {
93
- if (this.frame._secondaryWorld._hasContext()) {
94
- const result = await this.frame._secondaryWorld.evaluateHandle(code, puppeteerJsHandle_1.PuppeteerJsHandle.unwrapProperties(arg));
95
- return new puppeteerJsHandle_1.PuppeteerJsHandle(result, this.parentPage);
96
- }
97
- loggingProvider_1.logger.debug('Using primary world to evaluate handle instead of secondary world');
98
- return new puppeteerJsHandle_1.PuppeteerJsHandle(await this.frame.evaluateHandle(code, puppeteerJsHandle_1.PuppeteerJsHandle.unwrapProperties(arg)), this.parentPage);
99
- }
100
- async waitForSelector(selector, options) {
101
- const handle = await this.frame.waitForSelector(selector, (0, puppeteerBrowserLauncher_1.convertWaitForOptions)(options));
102
- return (0, utils_1.mapIfNotNull)(handle, (handle) => new puppeteerElementHandle_1.PuppeteerElementHandle(handle, this.parentPage));
103
- }
104
- async getFrameOwnerElement() {
105
- const parentFrame = this.parentFrame();
106
- if (!parentFrame) {
107
- return undefined;
108
- }
109
- const nodeInfo = await parentFrame.makeCdpCall('DOM.getFrameOwner', {
110
- frameId: this.frame._id,
111
- });
112
- return executionContext._adoptBackendNodeId(nodeInfo.backendNodeId);
113
- }
114
- }
115
- exports.PuppeteerFrame = PuppeteerFrame;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PuppeteerHttpRequest = void 0;
4
- const utils_1 = require("../utils");
5
- class PuppeteerHttpRequest {
6
- constructor(request, parentPage) {
7
- this.request = request;
8
- this.parentPage = parentPage;
9
- }
10
- continue() {
11
- return this.request.continue();
12
- }
13
- abort() {
14
- return this.request.abort();
15
- }
16
- respond(response) {
17
- var _a;
18
- return this.request.respond({
19
- status: response.status,
20
- contentType: response.contentType,
21
- headers: (_a = response.headers) !== null && _a !== void 0 ? _a : {},
22
- body: response.body,
23
- });
24
- }
25
- frame() {
26
- return (0, utils_1.mapIfNotNull)(this.request.frame(), (frame) => this.parentPage.getOrCreateFrame(frame));
27
- }
28
- url() {
29
- return this.request.url();
30
- }
31
- requestId() {
32
- return this.request._requestId;
33
- }
34
- headers() {
35
- return Promise.resolve(this.request.headers());
36
- }
37
- }
38
- exports.PuppeteerHttpRequest = PuppeteerHttpRequest;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PuppeteerHttpResponse = void 0;
4
- const utils_1 = require("../utils");
5
- const puppeteerHttpRequest_1 = require("./puppeteerHttpRequest");
6
- class PuppeteerHttpResponse {
7
- constructor(response, parentPage) {
8
- this.response = response;
9
- this.parentPage = parentPage;
10
- }
11
- headers() {
12
- return this.response.headers();
13
- }
14
- url() {
15
- return this.response.url();
16
- }
17
- frame() {
18
- return (0, utils_1.mapIfNotNull)(this.response.frame(), (frame) => this.parentPage.getOrCreateFrame(frame));
19
- }
20
- request() {
21
- return new puppeteerHttpRequest_1.PuppeteerHttpRequest(this.response.request(), this.parentPage);
22
- }
23
- json() {
24
- return this.response.json();
25
- }
26
- }
27
- exports.PuppeteerHttpResponse = PuppeteerHttpResponse;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PuppeteerJsHandle = void 0;
4
- const utils_1 = require("../utils");
5
- const puppeteerElementHandle_1 = require("./puppeteerElementHandle");
6
- class PuppeteerJsHandle {
7
- constructor(handle, parentPage) {
8
- this.handle = handle;
9
- this.parentPage = parentPage;
10
- }
11
- async evaluateHandle(code, arg) {
12
- const handle = await this.handle.evaluateHandle(code, PuppeteerJsHandle.unwrapProperties(arg));
13
- return (0, utils_1.mapIfNotNull)(handle, (handle) => new PuppeteerJsHandle(handle, this.parentPage));
14
- }
15
- asElement() {
16
- return (0, utils_1.mapIfNotNull)(this.handle.asElement(), (handle) => new puppeteerElementHandle_1.PuppeteerElementHandle(handle, this.parentPage));
17
- }
18
- jsonValue() {
19
- return this.handle.jsonValue();
20
- }
21
- async getProperty(propertyName) {
22
- return (0, utils_1.mapIfNotNull)(await this.handle.getProperty(propertyName), (handle) => new PuppeteerJsHandle(handle, this.parentPage));
23
- }
24
- evaluate(pageFunction, arg) {
25
- return this.handle.evaluate(pageFunction, PuppeteerJsHandle.unwrapProperties(arg));
26
- }
27
- getPuppeteerHandle() {
28
- return this.handle;
29
- }
30
- static unwrapProperties(arg) {
31
- return arg instanceof PuppeteerJsHandle
32
- ? arg.getPuppeteerHandle()
33
- : arg;
34
- }
35
- }
36
- exports.PuppeteerJsHandle = PuppeteerJsHandle;