twitter-api-browser-js 0.0.10 → 0.0.11

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/main.d.ts CHANGED
@@ -47,5 +47,5 @@ export declare class TwitterAPIBrowser {
47
47
  * @param fieldToggles - The fields to toggle on or off in the operation
48
48
  * @returns Response of the request
49
49
  */
50
- request<T extends keyof TwitterOpenAPIModelsMapping = string>(operationName: T, variables: LooseType, fieldToggles?: Record<string, boolean>, features?: Record<string, LooseType>): Promise<SuccessResponse<T> | LooseErrorResponse>;
50
+ request<T extends keyof TwitterOpenAPIModelsMapping = string>(operationName: T, variables: LooseType, fieldToggles?: Record<string, boolean>, features?: Record<string, LooseType> | null): Promise<SuccessResponse<T> | LooseErrorResponse>;
51
51
  }
package/dist/main.js CHANGED
@@ -62,7 +62,7 @@ export class TwitterAPIBrowser {
62
62
  await this.page.addInitScript(SETUP_SCRIPT);
63
63
  await this.page.addInitScript(OPERATIONS_SCRIPT);
64
64
  await this.page.addInitScript(INITIAL_STATE_SCRIPT);
65
- await this.page.goto("https://x.com/home");
65
+ await this.page.goto("https://x.com/login");
66
66
  await sleep(waitForReady * 1000);
67
67
  this.operations = await this.page.evaluate(`globalThis.${OPERATIONS_GLOBAL_KEY}`);
68
68
  this.initialState = await this.page.evaluate(`globalThis.${INITIAL_STATE_GLOBAL_KEY}`);
@@ -144,16 +144,21 @@ export class TwitterAPIBrowser {
144
144
  }
145
145
  await this.page.evaluate(SETUP_SCRIPT);
146
146
  await sleep(500);
147
- const response = [
148
- await this.page.evaluate(`globalThis.${REQUEST_FUNC_GLOBAL_KEY}(${JSON.stringify(removeNullRecursively(args))})`),
149
- ].flat();
150
- const result = pickFirstItem(response, "response");
151
- if (result instanceof Error) {
152
- console.log(`!!! Please report this error to the developer !!!`);
153
- throw result;
154
- }
155
- // TODO: more strict type check
156
- return result;
147
+ try {
148
+ const response = [
149
+ await this.page.evaluate(`globalThis.${REQUEST_FUNC_GLOBAL_KEY}(${JSON.stringify(removeNullRecursively(args))})`),
150
+ ].flat();
151
+ const result = pickFirstItem(response, "response");
152
+ if (result instanceof Error) {
153
+ console.log(`!!! Please report this error to the developer !!!`);
154
+ throw result;
155
+ }
156
+ // TODO: more strict type check
157
+ return result;
158
+ }
159
+ catch (e) {
160
+ throw e;
161
+ }
157
162
  }
158
163
  /**
159
164
  * Sends a request to the Twitter API
@@ -162,7 +167,7 @@ export class TwitterAPIBrowser {
162
167
  * @param fieldToggles - The fields to toggle on or off in the operation
163
168
  * @returns Response of the request
164
169
  */
165
- async request(operationName, variables, fieldToggles = {}, features = {}) {
170
+ async request(operationName, variables, fieldToggles = {}, features = null) {
166
171
  if (!this.page || !this.operations || !this.initialState) {
167
172
  throw new Error("Maybe you forgot to call setup()?");
168
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twitter-api-browser-js",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "types": "./dist/main.d.ts",
12
12
  "dependencies": {
13
- "playwright": "npm:patchright@^1.57.0",
13
+ "playwright": "^1.57.0",
14
14
  "twitter-openapi-typescript-generated": "^0.0.38"
15
15
  },
16
16
  "devDependencies": {