@sovovs/bycli 2.1.28 → 2.1.30

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.
@@ -32,6 +32,7 @@ export declare class Page extends BasePage {
32
32
  goto(url: string, options?: {
33
33
  waitUntil?: 'load' | 'none';
34
34
  settleMs?: number;
35
+ stealth?: boolean;
35
36
  }): Promise<void>;
36
37
  /** Get the active page identity (targetId) */
37
38
  getActivePage(): string | undefined;
@@ -106,10 +106,13 @@ export class Page extends BasePage {
106
106
  }
107
107
  this._lastUrl = url;
108
108
  // Inject stealth + settle in a single round-trip instead of two sequential exec calls.
109
- // The stealth guard flag prevents double-injection; settle uses DOM stability detection.
109
+ // Some security-sensitive editors reject runtime environment patches, so callers can
110
+ // retain the normal DOM-settle behavior while opting out of stealth injection.
111
+ const useStealth = options?.stealth !== false;
110
112
  if (options?.waitUntil !== 'none') {
111
113
  const maxMs = options?.settleMs ?? 1000;
112
- const combinedCode = `${generateStealthJs()};\n${waitForDomStableJs(maxMs, Math.min(500, maxMs))}`;
114
+ const settleCode = waitForDomStableJs(maxMs, Math.min(500, maxMs));
115
+ const combinedCode = useStealth ? `${generateStealthJs()};\n${settleCode}` : settleCode;
113
116
  const combinedOpts = {
114
117
  code: combinedCode,
115
118
  ...this._cmdOpts(),
@@ -134,7 +137,7 @@ export class Page extends BasePage {
134
137
  }
135
138
  }
136
139
  }
137
- else {
140
+ else if (useStealth) {
138
141
  // Even with waitUntil='none', still inject stealth (best-effort)
139
142
  try {
140
143
  await sendCommand('exec', {
@@ -10,6 +10,26 @@ function normalizeRows(data) {
10
10
  return [data];
11
11
  return [{ value: data }];
12
12
  }
13
+ /**
14
+ * Render one cell for the flat text formats (table / plain / md / csv).
15
+ *
16
+ * Adapters occasionally expose a structured column (e.g. juejin/search's
17
+ * per-kind `extra`), which `String(v)` would turn into "[object Object]".
18
+ * JSON is lossless and still one line, so it degrades gracefully.
19
+ */
20
+ function formatCell(v) {
21
+ if (v === null || v === undefined)
22
+ return '';
23
+ if (typeof v === 'object') {
24
+ try {
25
+ return JSON.stringify(v);
26
+ }
27
+ catch {
28
+ return String(v);
29
+ }
30
+ }
31
+ return String(v);
32
+ }
13
33
  function resolveColumns(rows, opts) {
14
34
  return opts.columns ?? Object.keys(rows[0] ?? {});
15
35
  }
@@ -63,8 +83,7 @@ function renderTable(data, opts) {
63
83
  });
64
84
  for (const row of rows) {
65
85
  table.push(columns.map(c => {
66
- const v = row[c];
67
- return v === null || v === undefined ? '' : String(v);
86
+ return formatCell(row[c]);
68
87
  }));
69
88
  }
70
89
  console.log();
@@ -101,7 +120,9 @@ function renderPlain(data, opts) {
101
120
  }
102
121
  }
103
122
  rows.forEach((row, index) => {
104
- const entries = Object.entries(row).filter(([, value]) => value !== undefined && value !== null && String(value) !== '');
123
+ const entries = Object.entries(row)
124
+ .map(([key, value]) => [key, formatCell(value)])
125
+ .filter(([, value]) => value !== '');
105
126
  entries.forEach(([key, value]) => {
106
127
  console.log(`${key}: ${value}`);
107
128
  });
@@ -127,7 +148,7 @@ function renderMarkdown(data, opts) {
127
148
  console.log('| ' + columns.join(' | ') + ' |');
128
149
  console.log('| ' + columns.map(() => '---').join(' | ') + ' |');
129
150
  for (const row of rows) {
130
- console.log('| ' + columns.map(c => String(row[c] ?? '')).join(' | ') + ' |');
151
+ console.log('| ' + columns.map(c => formatCell(row[c])).join(' | ') + ' |');
131
152
  }
132
153
  }
133
154
  function renderCsv(data, opts) {
@@ -138,7 +159,7 @@ function renderCsv(data, opts) {
138
159
  console.log(columns.join(','));
139
160
  for (const row of rows) {
140
161
  console.log(columns.map(c => {
141
- const v = String(row[c] ?? '');
162
+ const v = formatCell(row[c]);
142
163
  return v.includes(',') || v.includes('"') || v.includes('\n') || v.includes('\r')
143
164
  ? `"${v.replace(/"/g, '""')}"` : v;
144
165
  }).join(','));
@@ -70,6 +70,7 @@ export interface IPage {
70
70
  goto(url: string, options?: {
71
71
  waitUntil?: 'load' | 'none';
72
72
  settleMs?: number;
73
+ stealth?: boolean;
73
74
  }): Promise<void>;
74
75
  evaluate<T = any>(js: string): Promise<T>;
75
76
  evaluate<Args extends unknown[], T>(fn: BrowserEvaluateFunction<Args, T>, ...args: Args): Promise<Awaited<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovovs/bycli",
3
- "version": "2.1.28",
3
+ "version": "2.1.30",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },