Skip to content
Agentmart
Submit a tool

tiktok-ensure-login

Use when a TikTok task requires an authenticated session but current login state is unknown — detects via DOM avatar/login button and prompts the user to log…

Skill by 271642183

IndexedMIT
Write a review

Chalk Labs

Need help deploying tiktok-ensure-login?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/271642183-tiktok-ensure-login

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use when a TikTok task requires an authenticated session but current login state is unknown — detects via DOM avatar/login button and prompts the user to log in manually in the open Chrome window

Use cases: productivity

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/tiktok-ensure-login

What's inside

Skill name
tiktok-ensure-login
Description
Use when a TikTok task requires an authenticated session but current login state is unknown — detects via DOM avatar/login button and prompts the user to log in manually in the open Chrome window
License
MIT
Instructions
93 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

## 为什么有这个 skill

TikTok web 的"发评论"必须登录态(未登录用户评论框 disabled 或被反爬拦截)。所有 `tiktok-*` 业务 skill 在执行前**必须**先调本 skill 确认登录态。

**本 skill 不自动登录**——登录由用户手动完成(v1 设计决策)。只检测 + 提示。

## 登录态判定(双层)

### Cookie 辅助(不可靠,HttpOnly)

```js
() => ({
  sessionid: document.cookie.includes('sessionid='),
  sid_tt: document.cookie.includes('sid_tt='),
  uid_tt: document.cookie.includes('uid_tt='),
})
```

命中任一即视为"有信号",但**不作为唯一判定**——TikTok 部分 cookie 是 HttpOnly,JS 读不到。

### DOM 主判

```js
() => {
  const CURRENT_USER_AVATAR_SELECTOR = 'a[data-e2e="nav-profile"]';  // header 区可见的当前用户入口
  const LOGIN_BUTTON_SELECTOR = '';  // 留空,用 JS 文本匹配兜底(TikTok 登录按钮 data-e2e 不稳定)

  const hasAvatar = !!document.querySelector(CURRENT_USER_AVATAR_SELECTOR);
  const hasLoginBtn = !!document.querySelector(LOGIN_BUTTON_SELECTOR) ||
                      Array.from(document.querySelectorAll('button, a'))
                        .some(el => /log\s*in|sign\s*up/i.test(el.textContent || ''));
  const onLoginPage = /\/login|\/signup/.test(location.pathname);
  const hasCaptcha = !!document.querySelector('[class*="captcha" i]:not([class*="Badge" i]), iframe[src*="captcha" i], iframe[src*="verify" i], [class*="SliderCaptcha" i], [class*="challenge" i]');

  return { hasAvatar, hasLoginBtn, onLoginPage, hasCaptcha };
}
```

判定规则:
- `hasAvatar && !hasLoginBtn && !onLoginPage && !hasCaptcha` → **已登录**
- `onLoginPage || (hasLoginBtn && !hasAvatar)` → **未登录**
- `hasCaptcha` → **`verify_required`**,暂停让用户手动通过
- 头像存在但登录按钮也存在 → **异常态**,返回 `inconsistent_state` 让上层决定

## 验证码检测(独立)

`[class*="captcha"], [class*="verify"], iframe[src*="captcha"]` 命中 → 返回 `verify_required`,提示用户在 Chrome 手动通过。**不自动重试**。

## 操作步骤

1. 调用 `browser-navigate` 到 `https://www.tiktok.com/`,等 `domcontentloaded`
2. 用 `evaluate_script` 跑上面的 DOM 判定函数
3. 若 `logged_in = true` → 提取当前用户标识:
   - `document.querySelector('[data-e2e="user-avatar"]')?.getAttribute('alt')` 或
   - 链接到 `/@<username>` 的 `a[href*="/@"]` 元素文本
   返回成功
4. 若 `logged_in = false`:
   a. 终端向用户提示:
      ```
      请在已打开的 Chrome 窗口中手动登录 TikTok。
      不要关闭该窗口;登录完成后告诉我"继续"。
      ```
   b. 启动轮询:每 2 秒重跑 DOM 判定,最多 `max_rounds` 轮,每轮 `max_wait_seconds` 秒超时
   c. 命中 → 跳到步骤 3 二次确认(防页面自动刷新导致误判)
5. 若 `verify_required`:返回,**不轮询**,让用户手动通过后重试
6. 超时仍未登录 → 返回 `{ logged_in: false, reason: 'timeout' }`

## 返回格式

成功:
```
已确认登录,当前用户:{nickname}
```

失败:
```
登录失败:{reason}
reason ∈ { timeout, verify_required, inconsistent_state, cli_unavailable }
```

## 经验与陷阱

- **HttpOnly cookie**:仅靠 `document.cookie.includes('sessionid=')` 不可靠,**必须**配合 DOM 判定
- **`sessionid` 跨域**:TikTok 的 sessionid 不是简单 `sessionid=`,可能是 `sessionid=xxx%3D%3D`,判断时用 `includes('sessionid=')` 即可
- **页面自动刷新**:登录完成后 TikTok 可能 reload 页面,DOM 判定瞬时返回不一致 → 二次确认防误判
- **不要用 tiktok.com 的 cookie 当唯一信号**:TikTok 跟 douyin 不同,未登录也能种下部分 cookie
- **不重试 verify_required**:验证码需要人眼判断,agent 重试无意义
- **`max_rounds` 上限由调用方决定**:skill 内部只做"单次判定 + 单轮轮询",调用方决定重试策略

## Selector 更新

DOM 判定里的 `CURRENT_USER_AVATAR_SELECTOR` 和 captcha selector 是探测后填入的。selector 失效 → 跑 `skills/tiktok-post-comment/scripts/probe-deep.mjs`(参见 [skills/tiktok-post-comment/SKILL.md](../tiktok-post-comment/SKILL.md))重新探测,不盲猜。

From 271642183/tiktok-web-skills, MIT.

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Aug 10, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from 271642183

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get tiktok-ensure-login running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying tiktok-ensure-login?

CallGet help
Cite this page

tiktok-ensure-login skill. Agent Mart. https://agentmart.dev/skills/271642183-tiktok-ensure-login (last updated 2026-10-24)