pi-smart-fetch 0.2.30 → 0.2.31

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.js CHANGED
@@ -10205,25 +10205,10 @@ function createDefuddleFetch(dependencies = runtimeDependencies) {
10205
10205
  });
10206
10206
  const fallbackDocument = parseLinkedomHTML(rawBody, finalUrl);
10207
10207
  const extractionDocument = parseLinkedomHTML(rawBody, finalUrl);
10208
- if (isTwitterJsDisabledPage(fallbackDocument, opts.url)) {
10209
- return {
10210
- error: `Server returned HTTP 404 Not Found for ${opts.url}.`,
10211
- code: "http_error",
10212
- phase: "loading",
10213
- retryable: false,
10214
- timeoutMs,
10215
- url: opts.url,
10216
- finalUrl,
10217
- statusCode: 404,
10218
- statusText: "Not Found",
10219
- mimeType: normalizeContentType(contentType) || void 0,
10220
- contentLength: errorContext.contentLength
10221
- };
10222
- }
10223
10208
  let extracted;
10209
+ const suppressedErrors = [];
10224
10210
  try {
10225
10211
  const origConsoleError = console.error;
10226
- const suppressedErrors = [];
10227
10212
  console.error = (...args) => {
10228
10213
  suppressedErrors.push(args);
10229
10214
  };
@@ -10246,6 +10231,35 @@ function createDefuddleFetch(dependencies = runtimeDependencies) {
10246
10231
  wordCount: 0
10247
10232
  };
10248
10233
  }
10234
+ const isXUrl = /^https?:\/\/(www\.)?(x\.com|twitter\.com)\//i.test(
10235
+ opts.url
10236
+ );
10237
+ if (isXUrl) {
10238
+ const hasOembed404 = suppressedErrors.some(
10239
+ (args) => args.some(
10240
+ (arg) => typeof arg === "string" && arg.includes("oEmbed request failed: 404")
10241
+ )
10242
+ );
10243
+ const hasJsDisabledShell = isTwitterJsDisabledPage(
10244
+ fallbackDocument,
10245
+ opts.url
10246
+ );
10247
+ if (hasOembed404 || hasJsDisabledShell) {
10248
+ return {
10249
+ error: `Server returned HTTP 404 Not Found for ${opts.url}.`,
10250
+ code: "http_error",
10251
+ phase: "loading",
10252
+ retryable: false,
10253
+ timeoutMs,
10254
+ url: opts.url,
10255
+ finalUrl,
10256
+ statusCode: 404,
10257
+ statusText: "Not Found",
10258
+ mimeType: normalizeContentType(contentType) || void 0,
10259
+ contentLength: errorContext.contentLength
10260
+ };
10261
+ }
10262
+ }
10249
10263
  let extractedContent = extracted.content;
10250
10264
  let wordCount = extracted.wordCount;
10251
10265
  if (!extractedContent || wordCount === 0) {