@@ -23,6 +23,26 @@ const userDataDir = app.getPath("userData");
2323/** @type {BrowserContext | null } */
2424let browser ;
2525
26+ async function launchBrowser ( ) {
27+ const context = await chromium . launchPersistentContext (
28+ path . join ( userDataDir , "browser_data" ) ,
29+ {
30+ headless : false ,
31+ channel : "chrome" ,
32+ args : [
33+ "--disable-blink-features=AutomationControlled" ,
34+ "--disable-infobars" , // hides "Chrome is being controlled" banner
35+ ] ,
36+ userAgent :
37+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" ,
38+ viewport : null ,
39+ ignoreDefaultArgs : [ "--enable-automation" ] ,
40+ }
41+ ) ;
42+
43+ return context ;
44+ }
45+
2646/**
2747 * @typedef {Object } PublishData
2848 * @property {"youtube" | "bilibili" | "douyin" | "xiaohongshu" } channel - The platform to publish to
@@ -40,6 +60,11 @@ async function publishXiaohongshu(data) {
4060 browser = await launchBrowser ( ) ;
4161 }
4262 const page = await browser . newPage ( ) ;
63+ await page . addInitScript ( ( ) => {
64+ Object . defineProperty ( navigator , "webdriver" , {
65+ get : ( ) => false ,
66+ } ) ;
67+ } ) ;
4368 try {
4469 await page . goto ( "https://creator.xiaohongshu.com/publish/publish" ) ;
4570
@@ -106,8 +131,6 @@ async function fillXiaohongshuContent(page, title, content) {
106131 'input.d-text[placeholder="填写标题会有更多赞哦~"]' ,
107132 title || ""
108133 ) ;
109- // fill in title by typing
110- // await page.keyboard.type(title || "", { delay: 100 });
111134
112135 // Fill in the content by clipboard copying pasting
113136 await page . evaluate ( async ( text ) => {
@@ -172,16 +195,6 @@ async function waitForXiaohongshuUploadComplete(page) {
172195 return false ;
173196}
174197
175- async function launchBrowser ( ) {
176- return await chromium . launchPersistentContext (
177- path . join ( userDataDir , "browser_data" ) ,
178- {
179- headless : false ,
180- channel : "chrome" , // Use real Chrome
181- }
182- ) ;
183- }
184-
185198/**
186199 * @param {PublishData } data - The data for publishing the post
187200 */
0 commit comments