Skip to content

Commit 9dca5bd

Browse files
authored
tiktok behavior: (#116)
- click on 'comments' button, if available - better captcha detection - use 'not_logged_in' for now until more general reasons supported in Browsertrix - bump to 0.9.7
1 parent d157258 commit 9dca5bd

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browsertrix-behaviors",
3-
"version": "0.9.6",
3+
"version": "0.9.7",
44
"main": "index.js",
55
"author": "Webrecorder Software",
66
"license": "AGPL-3.0-or-later",

src/site/tiktok.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Q = {
2+
commentButton: "button[aria-label^='Read or add comments']",
23
commentList: "//div[contains(@class, 'CommentListContainer')]",
34
commentItem: "div[contains(@class, 'CommentItemContainer')]",
45
viewMoreReplies: ".//p[contains(@class, 'ReplyActionText')]",
@@ -15,7 +16,7 @@ export const BREADTH_ALL = Symbol("BREADTH_ALL");
1516
export class TikTokSharedBehavior {
1617
async awaitPageLoad(ctx: any) {
1718
const { assertContentValid, waitUntilNode } = ctx.Lib;
18-
await waitUntilNode(Q.pageLoadWaitUntil, document, null, 10000);
19+
await waitUntilNode(Q.pageLoadWaitUntil, document, null, 20000);
1920

2021
assertContentValid(
2122
() => !!document.querySelector("*[aria-label='Messages']"),
@@ -68,8 +69,27 @@ export class TikTokVideoBehavior extends TikTokSharedBehavior {
6869
scrollIntoView,
6970
getState,
7071
assertContentValid,
72+
sleep,
7173
} = ctx.Lib;
7274

75+
const showComments = document.querySelector(Q.commentButton);
76+
if (showComments) {
77+
(showComments as HTMLButtonElement).click();
78+
await sleep(10000);
79+
}
80+
81+
// assert no captcha every 0.5 seconds
82+
void (async () => {
83+
// eslint-disable-next-line no-constant-condition
84+
while (true) {
85+
if (document.querySelector("div[class*=captcha]")) {
86+
assertContentValid(false, "not_logged_in");
87+
break;
88+
}
89+
await sleep(500);
90+
}
91+
})();
92+
7393
const commentList = xpathNode(Q.commentList);
7494
const commentItems = iterChildMatches(Q.commentItem, commentList);
7595
for await (const item of commentItems) {
@@ -79,12 +99,6 @@ export class TikTokVideoBehavior extends TikTokSharedBehavior {
7999
yield* this.expandThread(ctx, item);
80100
}
81101

82-
// assert no captcha
83-
assertContentValid(
84-
() => !document.querySelector("div[class*=captcha]"),
85-
"captcha_found",
86-
);
87-
88102
yield getState(ctx, "TikTok Video Behavior Complete");
89103
}
90104
}

0 commit comments

Comments
 (0)