@thetypefounders/continue-with-google 1.2.0 → 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...');
@@ -19,7 +21,9 @@ export async function authenticate(page, email, password, secret, selector, opti
19
21
  await page.keyboard.press('Enter');
20
22
  for (let attempt = 0, found = false; attempt < (options.challengeCount || DEFAULTS.challengeCount) && !found; attempt++) {
21
23
  if (attempt > 0) {
22
- logger.info(`Challenged on attempt ${attempt}. Entering the code...`);
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,25 +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
- logger.info(`Tried on attempt ${attempt}. Taking a screenshot...`);
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
- else {
60
- logger.warn(`Failed to take a screenshot.`);
61
- }
62
65
  }
63
66
  }
64
- async function screenshot(page) {
67
+ async function takeScreenshotToCompare(page) {
65
68
  try {
66
69
  const content = '* { caret-color: transparent !important; }';
67
70
  await page.addStyleTag({ content });
@@ -71,3 +74,8 @@ async function screenshot(page) {
71
74
  return undefined;
72
75
  }
73
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.0",
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(
@@ -49,7 +53,8 @@ export async function authenticate(
49
53
  attempt++
50
54
  ) {
51
55
  if (attempt > 0) {
52
- logger.info(`Challenged on attempt ${attempt}. Entering the code...`);
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 (
@@ -94,22 +101,23 @@ async function waitForTrial(
94
101
  attempt++
95
102
  ) {
96
103
  if (attempt > 0) {
97
- logger.info(`Tried on attempt ${attempt}. Taking a screenshot...`);
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;
106
- } else {
107
- logger.warn(`Failed to take a screenshot.`);
108
114
  }
109
115
  }
110
116
  }
111
117
 
112
- async function screenshot(page: Page): Promise<string | undefined> {
118
+ async function takeScreenshotToCompare(
119
+ page: Page
120
+ ): Promise<string | undefined> {
113
121
  try {
114
122
  const content = '* { caret-color: transparent !important; }';
115
123
  await page.addStyleTag({ content });
@@ -118,3 +126,9 @@ async function screenshot(page: Page): Promise<string | undefined> {
118
126
  return undefined;
119
127
  }
120
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
+ }