@intuned/runtime-dev 1.7.0-dev-52-10 → 1.8.0-dev-52

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.
@@ -1,4 +1,4 @@
1
- import * as playwright from "playwright";
1
+ import * as playwright from "playwright-core";
2
2
  interface StorageEntry {
3
3
  name: string;
4
4
  value: string;
@@ -1,4 +1,4 @@
1
- import * as playwright from "playwright";
1
+ import * as playwright from "playwright-core";
2
2
  import type { RunApiSession } from "./runApi";
3
3
  interface Proxy {
4
4
  server: string;
@@ -7,7 +7,7 @@ exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
7
7
  exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
8
8
  exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
9
9
  exports.loadSessionToContext = loadSessionToContext;
10
- var playwright = _interopRequireWildcard(require("playwright"));
10
+ var playwright = _interopRequireWildcard(require("playwright-core"));
11
11
  var _fsExtra = _interopRequireWildcard(require("fs-extra"));
12
12
  var fs = _fsExtra;
13
13
  var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
@@ -43,12 +43,19 @@ async function getProductionPlaywrightConstructs({
43
43
  if (headless) {
44
44
  extraArgs.push("--headless=new");
45
45
  }
46
+ const executablePath = playwright.chromium.executablePath();
47
+ const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
48
+ const isChrome127There = await (0, _fsExtra.exists)(chromium127Path);
49
+ const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${isChrome127There ? 127 : 125}.0.0.0 Safari/537.36`;
46
50
  const userDataDir = await createUserDirWithPreferences();
47
51
  const context = await playwright.chromium.launchPersistentContext(userDataDir, {
48
52
  headless,
49
- viewport: null,
53
+ ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
50
54
  proxy,
51
- downloadsPath
55
+ executablePath: isChrome127There ? chromium127Path : executablePath,
56
+ args: extraArgs,
57
+ downloadsPath,
58
+ userAgent
52
59
  });
53
60
  context.once("close", async () => {
54
61
  try {
@@ -69,13 +76,9 @@ async function getProductionPlaywrightConstructs({
69
76
  });
70
77
  }
71
78
  const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
72
- await context.addInitScript({
73
- path: assetsFile
74
- });
75
79
  let page = context.pages().at(0);
76
80
  if (page) {
77
81
  const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
78
- await page.evaluate(scriptString);
79
82
  } else {
80
83
  page = await context.newPage();
81
84
  }
@@ -84,6 +87,7 @@ async function getProductionPlaywrightConstructs({
84
87
  context
85
88
  };
86
89
  }
90
+ const getChromiumLaunchArgsToIgnore = () => ["--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-component-update", "--no-default-browser-check", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf", "--enable-use-zoom-for-dsf=false"];
87
91
  async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
88
92
  if (mode == "playwright-standalone") {
89
93
  if (!cdpAddress) {
@@ -96,15 +100,11 @@ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
96
100
  throw new Error("no context found");
97
101
  }
98
102
  const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
99
- await context.addInitScript({
100
- path: assetsFile
101
- });
102
103
  const pages = await context.pages();
103
104
  let page = null;
104
105
  if (pages.length > 0) {
105
106
  page = pages[0];
106
107
  const scriptString = await fs.readFile(assetsFile, "utf8");
107
- await page.evaluate(scriptString);
108
108
  } else {
109
109
  page = await context.newPage();
110
110
  }
@@ -155,7 +155,7 @@ async function loadSessionToContext({
155
155
  await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
156
156
  }
157
157
  async function getRemotePlaywrightContext(cdpAddress) {
158
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
158
+ const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright-core")));
159
159
  let browser = null;
160
160
  if (!cdpAddress) {
161
161
  throw new Error("cdpAddress is required");
@@ -36,7 +36,8 @@ class JwtTokenManager {
36
36
  return Math.max(timeToRefresh, timeWindow);
37
37
  }
38
38
  async scheduleTokenRefresh() {
39
- if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
39
+ var _process$env$RUN_ENVI;
40
+ if (((_process$env$RUN_ENVI = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI === void 0 ? void 0 : _process$env$RUN_ENVI.toLowerCase()) !== "authoring") return;
40
41
  const timeToRefresh = this.timeToRefresh;
41
42
  if (timeToRefresh === undefined) return;
42
43
  if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
@@ -50,7 +51,8 @@ class JwtTokenManager {
50
51
  }, timeToRefresh);
51
52
  }
52
53
  async refreshToken() {
53
- if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
54
+ var _process$env$RUN_ENVI2;
55
+ if (((_process$env$RUN_ENVI2 = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI2 === void 0 ? void 0 : _process$env$RUN_ENVI2.toLowerCase()) !== "authoring") return;
54
56
  const res = await this.fetchWithToken(this.refreshTokenPath, {
55
57
  method: "GET"
56
58
  });
@@ -63,7 +65,7 @@ class JwtTokenManager {
63
65
  if (newToken) this._token = newToken;
64
66
  }
65
67
  fetchWithToken(...[input, init]) {
66
- const headers = new Headers(init?.headers);
68
+ const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
67
69
  headers.set("Authorization", `Bearer ${this.token}`);
68
70
  return (0, _crossFetch.default)(input, {
69
71
  ...init,
@@ -22,10 +22,11 @@ const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundEr
22
22
  class RunAutomationError {
23
23
  wrapped = false;
24
24
  get json() {
25
+ var _this$cause;
25
26
  return {
26
27
  code: this.code,
27
28
  details: this.details,
28
- cause: this.cause?.json
29
+ cause: (_this$cause = this.cause) === null || _this$cause === void 0 ? void 0 : _this$cause.json
29
30
  };
30
31
  }
31
32
  }
@@ -135,10 +136,10 @@ class AutomationError extends RunAutomationError {
135
136
  };
136
137
  }
137
138
  this.statusCode = 500;
138
- this.message = `[${error?.name ?? error}] ${error?.message}`;
139
+ this.message = `[${(error === null || error === void 0 ? void 0 : error.name) ?? error}] ${error === null || error === void 0 ? void 0 : error.message}`;
139
140
  this.details = {
140
- name: error?.name,
141
- message: error?.message
141
+ name: error === null || error === void 0 ? void 0 : error.name,
142
+ message: error === null || error === void 0 ? void 0 : error.message
142
143
  };
143
144
  }
144
145
  }
@@ -1,6 +1,6 @@
1
1
  import { Result } from "neverthrow";
2
2
  import { RunAutomationError } from "./errors";
3
- import { Page, BrowserContext } from "playwright";
3
+ import { Page, BrowserContext } from "playwright-core";
4
4
  import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
5
5
  export * from "./types";
6
6
  export * from "./errors";
@@ -80,15 +80,17 @@ async function* runApiGenerator({
80
80
  return;
81
81
  }
82
82
  try {
83
- await context?.tracing.stop({
83
+ var _context;
84
+ await ((_context = context) === null || _context === void 0 ? void 0 : _context.tracing.stop({
84
85
  path: tracing.filePath
85
- });
86
+ }));
86
87
  } catch (error) {
87
- console.log(errorMessage, error?.message);
88
+ console.log(errorMessage, error === null || error === void 0 ? void 0 : error.message);
88
89
  await (0, _fsExtra.remove)(tracing.filePath);
89
90
  }
90
91
  }
91
92
  async function* runAutomation() {
93
+ var _getExecutionContext;
92
94
  let page;
93
95
  const validatedModuleResult = await importUsingImportFunction(automationFunction.name, importFunction);
94
96
  if (validatedModuleResult.isErr()) {
@@ -96,7 +98,7 @@ async function* runApiGenerator({
96
98
  }
97
99
  const importedModule = validatedModuleResult.value;
98
100
  let checkFn;
99
- if (auth?.runCheck) {
101
+ if (auth !== null && auth !== void 0 && auth.runCheck) {
100
102
  if (!auth.session) {
101
103
  return (0, _neverthrow.err)(new _errors.AuthRequiredError());
102
104
  }
@@ -128,7 +130,7 @@ async function* runApiGenerator({
128
130
  headless,
129
131
  proxy,
130
132
  downloadsPath,
131
- storageState: auth?.session
133
+ storageState: auth === null || auth === void 0 ? void 0 : auth.session
132
134
  }));
133
135
  } else {
134
136
  const {
@@ -138,7 +140,7 @@ async function* runApiGenerator({
138
140
  ({
139
141
  page,
140
142
  context
141
- } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth?.session));
143
+ } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
142
144
  }
143
145
  if (tracing.enabled) {
144
146
  await context.tracing.start({
@@ -183,7 +185,7 @@ async function* runApiGenerator({
183
185
  }
184
186
  return (0, _neverthrow.ok)({
185
187
  result,
186
- extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
188
+ extendedPayloads: (_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
187
189
  session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
188
190
  });
189
191
  }
@@ -204,10 +206,11 @@ async function* runApiGenerator({
204
206
  } catch (error) {
205
207
  return (0, _neverthrow.err)(new _errors.AutomationError(error));
206
208
  } finally {
209
+ var _context2;
207
210
  await saveTraceIfNeeded({
208
211
  errorMessage: "failed to save trace"
209
212
  });
210
- await context?.close();
213
+ await ((_context2 = context) === null || _context2 === void 0 ? void 0 : _context2.close());
211
214
  if (downloadsPath !== undefined) {
212
215
  await fs.remove(downloadsPath);
213
216
  }
@@ -24,12 +24,13 @@ var _enums = require("./enums");
24
24
  runId: "test-run-id",
25
25
  extendedPayloads: []
26
26
  }, () => {
27
- (0, _vitest.expect)((0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads).toEqual([]);
27
+ var _getExecutionContext, _getExecutionContext2;
28
+ (0, _vitest.expect)((_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
28
29
  (0, _.extendPayload)({
29
30
  api: "test-api",
30
31
  parameters: {}
31
32
  });
32
- (0, _vitest.expect)((0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads).toEqual([{
33
+ (0, _vitest.expect)((_getExecutionContext2 = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
33
34
  api: "test-api",
34
35
  parameters: {}
35
36
  }]);
@@ -46,7 +47,7 @@ var _enums = require("./enums");
46
47
  parameters: {}
47
48
  });
48
49
  const context = (0, _asyncLocalStorage.getExecutionContext)();
49
- (0, _vitest.expect)(context?.extendedPayloads).toHaveLength(4);
50
+ (0, _vitest.expect)(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
50
51
  });
51
52
  });
52
53
  });
@@ -201,18 +201,3 @@ export declare function requestMultipleChoice(
201
201
  * ```
202
202
  */
203
203
  export declare function requestOTP(message: string): unknown;
204
-
205
- /**
206
- * Retrieves the parameters for the authentication session currently being used.
207
- *
208
- * @returns {AuthSessionParameters} An object containing the parameters for the current authentication session.
209
- *
210
- * @example
211
- * ```typescript getAuthSessionParameters
212
- * import { getAuthSessionParameters } from "@intuned/sdk/runtime"
213
- *
214
- * const authSessionParams = getAuthSessionParameters();
215
- * console.log(authSessionParams);
216
- * ```
217
- */
218
- export declare function getAuthSessionParameters(): Promise<any>;
@@ -16,6 +16,6 @@ function extendPayload(payload) {
16
16
  context.extendedPayloads = [...items];
17
17
  return;
18
18
  }
19
- context?.extendedPayloads.push(...items);
19
+ context === null || context === void 0 || context.extendedPayloads.push(...items);
20
20
  (0, _extendTimeout.extendTimeout)();
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.7.0-dev-52-10",
3
+ "version": "1.8.0-dev-52",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -130,6 +130,7 @@
130
130
  "vitest": "^1.1.3"
131
131
  },
132
132
  "peerDependencies": {
133
- "playwright": "*"
133
+ "playwright": "*",
134
+ "playwright-core": "*"
134
135
  }
135
136
  }