@thetypefounders/continue-with-google 1.2.1 → 1.3.0

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/dist/index.d.ts CHANGED
@@ -6,8 +6,10 @@ export interface Logger {
6
6
  export type Options = {
7
7
  challengeCount?: number;
8
8
  challengeTimeoutSeconds?: number;
9
+ challengeScreenshot?: boolean;
9
10
  trialCount?: number;
10
11
  trialTimeoutSeconds?: number;
12
+ trialScreenshot?: boolean;
11
13
  waitForSelector?: WaitForSelectorOptions;
12
14
  };
13
15
  export declare function authenticate(page: Page, email: string, password: string, secret: string, selector: string, options?: Options, logger?: Logger): Promise<ElementHandle | null>;
package/dist/index.js CHANGED
@@ -3,8 +3,10 @@ import { setTimeout } from 'node:timers/promises';
3
3
  const DEFAULTS = {
4
4
  challengeCount: 3,
5
5
  challengeTimeoutSeconds: 30,
6
+ challengeScreenshot: false,
6
7
  trialCount: 10,
7
8
  trialTimeoutSeconds: 2,
9
+ trialScreenshot: false,
8
10
  };
9
11
  export async function authenticate(page, email, password, secret, selector, options = DEFAULTS, logger = console) {
10
12
  logger.info('Waiting to enter the email...');
@@ -20,6 +22,8 @@ export async function authenticate(page, email, password, secret, selector, opti
20
22
  for (let attempt = 0, found = false; attempt < (options.challengeCount || DEFAULTS.challengeCount) && !found; attempt++) {
21
23
  if (attempt > 0) {
22
24
  logger.warn(`Challenged on attempt ${attempt}. Entering the code...`);
25
+ if (options.challengeScreenshot)
26
+ await takeScreenshotToDisplay(page);
23
27
  if (attempt > 1) {
24
28
  await setTimeout(1000 *
25
29
  (options.challengeTimeoutSeconds ||
@@ -32,7 +36,7 @@ export async function authenticate(page, email, password, secret, selector, opti
32
36
  });
33
37
  await page.type('input[type=tel]', code);
34
38
  await page.keyboard.press('Enter');
35
- await waitForTrial(page, options.trialCount || DEFAULTS.trialCount, options.trialTimeoutSeconds || DEFAULTS.trialTimeoutSeconds, logger);
39
+ await waitForTrial(page, options.trialCount || DEFAULTS.trialCount, options.trialTimeoutSeconds || DEFAULTS.trialTimeoutSeconds, options.trialScreenshot || DEFAULTS.trialScreenshot, logger);
36
40
  }
37
41
  found = await Promise.any([
38
42
  page.waitForSelector(selector, options.waitForSelector).then(() => true),
@@ -43,22 +47,24 @@ export async function authenticate(page, email, password, secret, selector, opti
43
47
  }
44
48
  return await page.$(selector);
45
49
  }
46
- async function waitForTrial(page, attemptCount, attemptTimeoutSeconds, logger) {
50
+ async function waitForTrial(page, attemptCount, attemptTimeoutSeconds, attemptScreenshot, logger) {
47
51
  for (let attempt = -1, previous = undefined, current = undefined; attempt < attemptCount && (current === undefined || previous !== current); attempt++) {
48
52
  if (attempt > 0) {
49
53
  logger.warn(`Tried on attempt ${attempt}. Waiting to finish...`);
54
+ if (attemptScreenshot)
55
+ await takeScreenshotToDisplay(page);
50
56
  }
51
57
  if (attempt > -1) {
52
58
  await setTimeout(1000 * attemptTimeoutSeconds);
53
59
  }
54
- const future = await screenshot(page);
60
+ const future = await takeScreenshotToCompare(page);
55
61
  if (future) {
56
62
  previous = current;
57
63
  current = future;
58
64
  }
59
65
  }
60
66
  }
61
- async function screenshot(page) {
67
+ async function takeScreenshotToCompare(page) {
62
68
  try {
63
69
  const content = '* { caret-color: transparent !important; }';
64
70
  await page.addStyleTag({ content });
@@ -68,3 +74,8 @@ async function screenshot(page) {
68
74
  return undefined;
69
75
  }
70
76
  }
77
+ async function takeScreenshotToDisplay(page) {
78
+ await page.screenshot({
79
+ path: `continue-with-google-${new Date(Date.now()).toISOString()}.png`,
80
+ });
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thetypefounders/continue-with-google",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Ivan Ukhov <ivan.ukhov@gmail.com>",
6
6
  "description": "Two-factor authentication with Google via Puppeteer",
@@ -13,13 +13,13 @@
13
13
  "types": "dist/index.d.ts",
14
14
  "dependencies": {
15
15
  "authenticator": "^1.1.5",
16
- "puppeteer": "^24.1.1"
16
+ "puppeteer": "^24.9.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@trivago/prettier-plugin-sort-imports": "^5.2.1",
19
+ "@trivago/prettier-plugin-sort-imports": "^5.2.2",
20
20
  "@types/authenticator": "^1.1.4",
21
- "prettier": "^3.4.2",
22
- "typescript": "^5.7.3"
21
+ "prettier": "^3.5.3",
22
+ "typescript": "^5.8.3"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc",
package/src/index.ts CHANGED
@@ -10,16 +10,20 @@ export interface Logger {
10
10
  export type Options = {
11
11
  challengeCount?: number;
12
12
  challengeTimeoutSeconds?: number;
13
+ challengeScreenshot?: boolean;
13
14
  trialCount?: number;
14
15
  trialTimeoutSeconds?: number;
16
+ trialScreenshot?: boolean;
15
17
  waitForSelector?: WaitForSelectorOptions;
16
18
  };
17
19
 
18
20
  const DEFAULTS: Options = {
19
21
  challengeCount: 3,
20
22
  challengeTimeoutSeconds: 30,
23
+ challengeScreenshot: false,
21
24
  trialCount: 10,
22
25
  trialTimeoutSeconds: 2,
26
+ trialScreenshot: false,
23
27
  };
24
28
 
25
29
  export async function authenticate(
@@ -50,6 +54,7 @@ export async function authenticate(
50
54
  ) {
51
55
  if (attempt > 0) {
52
56
  logger.warn(`Challenged on attempt ${attempt}. Entering the code...`);
57
+ if (options.challengeScreenshot) await takeScreenshotToDisplay(page);
53
58
  if (attempt > 1) {
54
59
  await setTimeout(
55
60
  1000 *
@@ -68,6 +73,7 @@ export async function authenticate(
68
73
  page,
69
74
  options.trialCount || DEFAULTS.trialCount!,
70
75
  options.trialTimeoutSeconds || DEFAULTS.trialTimeoutSeconds!,
76
+ options.trialScreenshot || DEFAULTS.trialScreenshot!,
71
77
  logger
72
78
  );
73
79
  }
@@ -86,6 +92,7 @@ async function waitForTrial(
86
92
  page: Page,
87
93
  attemptCount: number,
88
94
  attemptTimeoutSeconds: number,
95
+ attemptScreenshot: boolean,
89
96
  logger: Logger
90
97
  ): Promise<void> {
91
98
  for (
@@ -95,11 +102,12 @@ async function waitForTrial(
95
102
  ) {
96
103
  if (attempt > 0) {
97
104
  logger.warn(`Tried on attempt ${attempt}. Waiting to finish...`);
105
+ if (attemptScreenshot) await takeScreenshotToDisplay(page);
98
106
  }
99
107
  if (attempt > -1) {
100
108
  await setTimeout(1000 * attemptTimeoutSeconds);
101
109
  }
102
- const future = await screenshot(page);
110
+ const future = await takeScreenshotToCompare(page);
103
111
  if (future) {
104
112
  previous = current;
105
113
  current = future;
@@ -107,7 +115,9 @@ async function waitForTrial(
107
115
  }
108
116
  }
109
117
 
110
- async function screenshot(page: Page): Promise<string | undefined> {
118
+ async function takeScreenshotToCompare(
119
+ page: Page
120
+ ): Promise<string | undefined> {
111
121
  try {
112
122
  const content = '* { caret-color: transparent !important; }';
113
123
  await page.addStyleTag({ content });
@@ -116,3 +126,9 @@ async function screenshot(page: Page): Promise<string | undefined> {
116
126
  return undefined;
117
127
  }
118
128
  }
129
+
130
+ async function takeScreenshotToDisplay(page: Page): Promise<void> {
131
+ await page.screenshot({
132
+ path: `continue-with-google-${new Date(Date.now()).toISOString()}.png`,
133
+ });
134
+ }