@@ -132,10 +132,6 @@ export class Bridge extends EventEmitter {
132
132
launchOptions . executablePath = this . options . endpoint
133
133
}
134
134
135
- const extensionOptionsArgs = [
136
- ...this . getWeChromeExtensionOptionsArgs ( ) ,
137
- ]
138
-
139
135
const options = {
140
136
...launchOptions ,
141
137
args : [
@@ -149,7 +145,6 @@ export class Bridge extends EventEmitter {
149
145
'--mute-audio' ,
150
146
'--no-sandbox' ,
151
147
...launchOptionsArgs ,
152
- ...extensionOptionsArgs ,
153
148
] ,
154
149
headless,
155
150
}
@@ -230,6 +225,12 @@ export class Bridge extends EventEmitter {
230
225
// might be called before initPage() return.
231
226
const page = this . page = await browser . newPage ( )
232
227
228
+ /**
229
+ * Can we support UOS with puppeteer? #127
230
+ * https://github.com/wechaty/wechaty-puppet-wechat/issues/127
231
+ */
232
+ await this . uosPatch ( page )
233
+
233
234
page . on ( 'error' , e => this . emit ( 'error' , e ) )
234
235
page . on ( 'dialog' , this . onDialog . bind ( this ) )
235
236
@@ -268,36 +269,26 @@ export class Bridge extends EventEmitter {
268
269
const UOS_PATCH_CLIENT_VERSION = '2.0.0'
269
270
const UOS_PATCH_EXTSPAM = 'Gp8ICJkIEpkICggwMDAwMDAwMRAGGoAI1GiJSIpeO1RZTq9QBKsRbPJdi84ropi16EYI10WB6g74sGmRwSNXjPQnYUKYotKkvLGpshucCaeWZMOylnc6o2AgDX9grhQQx7fm2DJRTyuNhUlwmEoWhjoG3F0ySAWUsEbH3bJMsEBwoB//0qmFJob74ffdaslqL+IrSy7LJ76/G5TkvNC+J0VQkpH1u3iJJs0uUYyLDzdBIQ6Ogd8LDQ3VKnJLm4g/uDLe+G7zzzkOPzCjXL+70naaQ9medzqmh+/SmaQ6uFWLDQLcRln++wBwoEibNpG4uOJvqXy+ql50DjlNchSuqLmeadFoo9/mDT0q3G7o/80P15ostktjb7h9bfNc+nZVSnUEJXbCjTeqS5UYuxn+HTS5nZsPVxJA2O5GdKCYK4x8lTTKShRstqPfbQpplfllx2fwXcSljuYi3YipPyS3GCAqf5A7aYYwJ7AvGqUiR2SsVQ9Nbp8MGHET1GxhifC692APj6SJxZD3i1drSYZPMMsS9rKAJTGz2FEupohtpf2tgXm6c16nDk/cw+C7K7me5j5PLHv55DFCS84b06AytZPdkFZLj7FHOkcFGJXitHkX5cgww7vuf6F3p0yM/W73SoXTx6GX4G6Hg2rYx3O/9VU2Uq8lvURB4qIbD9XQpzmyiFMaytMnqxcZJcoXCtfkTJ6pI7a92JpRUvdSitg967VUDUAQnCXCM/m0snRkR9LtoXAO1FUGpwlp1EfIdCZFPKNnXMeqev0j9W9ZrkEs9ZWcUEexSj5z+dKYQBhIICviYUQHVqBTZSNy22PlUIeDeIs11j7q4t8rD8LPvzAKWVqXE+5lS1JPZkjg4y5hfX1Dod3t96clFfwsvDP6xBSe1NBcoKbkyGxYK0UvPGtKQEE0Se2zAymYDv41klYE9s+rxp8e94/H8XhrL9oGm8KWb2RmYnAE7ry9gd6e8ZuBRIsISlJAE/e8y8xFmP031S6Lnaet6YXPsFpuFsdQs535IjcFd75hh6DNMBYhSfjv456cvhsb99+fRw/KVZLC3yzNSCbLSyo9d9BI45Plma6V8akURQA/qsaAzU0VyTIqZJkPDTzhuCl92vD2AD/QOhx6iwRSVPAxcRFZcWjgc2wCKh+uCYkTVbNQpB9B90YlNmI3fWTuUOUjwOzQRxJZj11NsimjOJ50qQwTTFj6qQvQ1a/I+MkTx5UO+yNHl718JWcR3AXGmv/aa9rD1eNP8ioTGlOZwPgmr2sor2iBpKTOrB83QgZXP+xRYkb4zVC+LoAXEoIa1+zArywlgREer7DLePukkU6wHTkuSaF+ge5Of1bXuU4i938WJHj0t3D8uQxkJvoFi/EYN/7u2P1zGRLV4dHVUsZMGCCtnO6BBigFMAA='
270
271
271
- const extraHeaders = {
272
+ const uosHeaders = {
272
273
'client-version' : UOS_PATCH_CLIENT_VERSION ,
273
274
extspam : UOS_PATCH_EXTSPAM ,
274
- referer : 'https://wx.qq.com/?&lang=zh_CN&target=t' ,
275
275
}
276
- await page . setExtraHTTPHeaders ( extraHeaders )
277
- }
278
-
279
- private getWeChromeExtensionOptionsArgs ( ) : string [ ] {
280
- /**
281
- * Issue #127: Can we support UOS with puppeteer?
282
- * https://github.com/wechaty/wechaty-puppet-wechat/issues/127
283
- * https://github.com/adamyi/wechrome - Chrome extension to unblock web wechat
284
- * https://stackoverflow.com/a/51434261/1123955
285
- */
286
- const weChromeExt = path . join (
287
- __dirname ,
288
- '..' ,
289
- 'wechrome'
290
- )
291
- if ( ! fs . existsSync ( weChromeExt ) ) {
292
- throw new Error ( 'WeChrome extension not found.' )
293
- }
294
-
295
- const extensionOptionsArgs = [
296
- `--load-extension=${ weChromeExt } ` ,
297
- `--disable-extensions-except=${ weChromeExt } ` ,
298
- ]
299
-
300
- return extensionOptionsArgs
276
+ // add RequestInterception
277
+ await page . setRequestInterception ( true )
278
+ page . on ( 'request' , async req => {
279
+ const url = new URL ( req . url ( ) )
280
+ if ( url . pathname === '/cgi-bin/mmwebwx-bin/webwxnewloginpage' ) {
281
+ const override = {
282
+ headers : {
283
+ ...req . headers ( ) ,
284
+ ...uosHeaders ,
285
+ } ,
286
+ }
287
+ await req . continue ( override )
288
+ return
289
+ }
290
+ await req . continue ( )
291
+ } )
301
292
}
302
293
303
294
public async readyAngular ( page : Page ) : Promise < void > {
@@ -1050,7 +1041,10 @@ export class Bridge extends EventEmitter {
1050
1041
public entryUrl ( cookieList ?: Protocol . Network . Cookie [ ] ) : string {
1051
1042
log . verbose ( 'PuppetWeChatBridge' , 'cookieDomain(%s)' , cookieList )
1052
1043
1053
- const DEFAULT_URL = 'https://wx.qq.com'
1044
+ /**
1045
+ * `?target=t` is from https://github.com/wechaty/wechaty-puppet-wechat/pull/129
1046
+ */
1047
+ const DEFAULT_URL = 'https://wx.qq.com?target=t'
1054
1048
1055
1049
if ( ! cookieList || cookieList . length === 0 ) {
1056
1050
log . silly ( 'PuppetWeChatBridge' , 'cookieDomain() no cookie, return default %s' , DEFAULT_URL )
0 commit comments