Skip to content

fix(toutiao): fix NON_TITLE_LINES scope error in articles parser#1179

Open
sontjer wants to merge 1 commit intojackwener:mainfrom
sontjer:fix/toutiao-non-title-lines-scope
Open

fix(toutiao): fix NON_TITLE_LINES scope error in articles parser#1179
sontjer wants to merge 1 commit intojackwener:mainfrom
sontjer:fix/toutiao-non-title-lines-scope

Conversation

@sontjer
Copy link
Copy Markdown

@sontjer sontjer commented Apr 25, 2026

Bug Description

When running opencli toutiao articles, the command fails with:

ReferenceError: NON_TITLE_LINES is not defined
    at parseToutiaoArticlesText (<anonymous>:19:70)

Root Cause

NON_TITLE_LINES is defined as a module-level const outside parseToutiaoArticlesText(). The function is serialized via .toString() and injected into the browser's evaluate context for DOM parsing. Outer scope variables are not available in the injected execution context, causing the ReferenceError.

Fix

Move NON_TITLE_LINES inside the parseToutiaoArticlesText function so it's included in the serialized string.

-import { cli } from '@jackwener/opencli/registry';
-
-const NON_TITLE_LINES = new Set([...]);
-
 export function parseToutiaoArticlesText(text) {
+    const NON_TITLE_LINES = new Set([...]);
     const lines = String(text || '').split('\n').map(...);

Verification

$ opencli toutiao articles -f table
┌───────┬─────────────┬────────┬──────┬──────┬──────┬──────┐
│ Title │ Date        │ Status │ 展现 │ 阅读 │ 点赞 │ 评论 │
├───────┼─────────────┼────────┼──────┼──────┼──────┼──────┤
│ 高    │ 03-19 10:28 │ 已发布 │ 18   │ 1    │ 0    │ 0    │
└───────┴─────────────┴────────┴──────┴──────┴──────┴──────┘

Works correctly after the fix. Command was completely broken before.

NON_TITLE_LINES was defined outside parseToutiaoArticlesText() as a
module-level const. When the function is serialized via .toString()
and injected into browser evaluate context, outer scope variables
are not available, causing 'NON_TITLE_LINES is not defined' error.

Fix: move NON_TITLE_LINES inside the function so it's included in
the serialized string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant