Skip to content

[Bug]: 自己写的适配器,操作时打开的浏览器实例总是会遮挡正在正常使用的 chrome 实例 #1071

@lyc10031

Description

@lyc10031

Description

自己写的适配器,操作时打开的浏览器实例总是会遮挡正在正常使用的 chrome 实例

Steps to Reproduce

原始代码

import { cli, Strategy } from '@jackwener/opencli/registry';

cli({
site: 'gsmarena',
name: 'detail',
description: 'Get detailed device information from GSMArena',
domain: 'www.gsmarena.com',
strategy: Strategy.PUBLIC,
browser: true,
args: [
{
name: 'url',
required: true,
help: 'GSMArena device page URL',
},
],
func: async (page, kwargs) => {
console.log('kwargs:', JSON.stringify(kwargs));
const url = kwargs.url;
console.log('Navigating to:', url);
await page.goto(url);

// Wait for the page to load or handle turnstile
await new Promise(r => setTimeout(r, 5000));

// Check for turnstile
const isTurnstile = await page.evaluate(() => {
  return document.title === 'GSMArena Turnstile check' || !!document.querySelector('#ts-wrap');
});

if (isTurnstile) {
  console.log('Turnstile detected, clicking continue...');
  // Try to click continue if visible
  await page.evaluate(() => {
    const btn = document.querySelector('button[type="submit"]');
    if (btn) btn.click();
  });
  await new Promise(r => setTimeout(r, 10000));
}

// Extra wait for dynamic content
await new Promise(r => setTimeout(r, 2000));

const data = await page.evaluate(`(() => {
  const result = {};
  const tables = Array.from(document.querySelectorAll('table'));
  for (const table of tables) {
    const th = table.querySelector('th');
    const category = th ? th.textContent.trim() : 'General';
    if (!result[category]) result[category] = {};
    
    const trs = Array.from(table.querySelectorAll('tr'));
    for (const tr of trs) {
      const ttl = tr.querySelector('.ttl');
      const nfo = tr.querySelector('.nfo');
      if (ttl && nfo) {
        result[category][ttl.textContent.trim()] = nfo.textContent.trim();
      }
    }
  }
  return result;
})()`);

return [data];

},
});

  1. Run opencli gsmarena search --query "SM-S948E/DS" --limit 1 --detail -f json
  2. 会遮挡其他 chrome 实例

Expected Behavior

不遮挡,不影响其他 chrome 实例,自己默默的干活

OpenCLI Version

1.7.4

Node.js Version

22.x

Operating System

macOS

Logs / Screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions