Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
5d61a37a
W
wechaty
项目概览
weixin_46011646
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5d61a37a
编写于
8月 26, 2017
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
drop(phantomjs) not supported any more (#763)
上级
9d78e5c1
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
0 addition
and
140 deletion
+0
-140
test/webdriver-phantomjs.spec.ts
test/webdriver-phantomjs.spec.ts
+0
-140
未找到文件。
test/webdriver-phantomjs.spec.ts
已删除
100644 → 0
浏览文件 @
9d78e5c1
/**
* Wechaty - https://github.com/chatie/wechaty
*
* Copyright 2016-2017 Huan LI <zixia@zixia.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import
*
as
WebDriver
from
'
selenium-webdriver
'
import
*
as
express
from
'
express
'
import
*
as
http
from
'
http
'
import
*
as
url
from
'
url
'
/* tslint:disable:no-var-requires */
/* tslint:disable:variable-name */
const
Phantomjs
=
require
(
'
phantomjs-prebuilt
'
)
import
{
test
}
from
'
ava
'
import
{
UtilLib
}
from
'
../src/util-lib
'
test
.
skip
(
'
Phantomjs replace javascript source file content test
'
,
async
t
=>
{
const
phantomjsArgs
=
[
'
--load-images=false
'
,
'
--ignore-ssl-errors=true
'
,
// this help socket.io connect with localhost
'
--web-security=false
'
,
// https://github.com/ariya/phantomjs/issues/12440#issuecomment-52155299
'
--ssl-protocol=TLSv1
'
,
// https://github.com/ariya/phantomjs/issues/11239#issuecomment-42362211
'
--webdriver-loglevel=WARN
'
,
// , '--webdriver-loglevel=DEBUG'
// , '--webdriver-logfile=webdriver.debug.log'
// , '--remote-debugger-port=8080'
]
const
customPhantom
=
WebDriver
.
Capabilities
.
phantomjs
()
// .setAlertBehavior('ignore')
.
set
(
'
phantomjs.binary.path
'
,
Phantomjs
.
path
)
.
set
(
'
phantomjs.cli.args
'
,
phantomjsArgs
)
const
driver
=
new
WebDriver
.
Builder
()
.
withCapabilities
(
customPhantom
)
.
build
()
// http://stackoverflow.com/questions/24834403/phantomjs-change-webpage-content-before-evaluating
;
(
driver
as
any
).
executePhantomJS
(
`
this.onResourceRequested = function(request, net) {
console.log('REQUEST ' + request.url);
alert('REQUEST ' + request.url);
// blockRe = /wx\.qq\.com\/\?t=v2\/fake/i
// https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp2fd632.js
var webwxAppRe = /res\.wx\.qq\.com\/zh_CN\/htmledition\/v2\/js\/webwxApp.+\.js$/i
alert('################### matching ' + request.url)
if (webwxAppRe.test(request.url)) {
console.log('Abort ' + request.url);
net.abort();
alert('################### found ' + request.url)
var url = request.url + '?' + Date.now()
load(url, function(source) {
eval( fix(source) )
})
}
function load(url, cb) {
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
cb(xhr.responseText)
}
}
xhr.send(null)
}
}
function fix(source) {
// "54c6b762ad3618c9ebfd4b439c8d4bda" !== h && ($.getScript("https://tajs.qq.com/stats?sId=54802481"),
// location.href = "https://wx.qq.com/?t=v2/fake")
var fixRe = /"54c6b762ad3618c9ebfd4b439c8d4bda".+?&& \(.+?fake"\)/i
return source.replace(fixRe, '')
}
}
`
)
await
driver
.
get
(
'
https://wx.qq.com
'
)
// console.log(await driver.getTitle())
// t.end()
})
test
.
skip
(
'
TODO: Phantomjs http header
'
,
async
t
=>
{
const
port
=
await
UtilLib
.
getPort
(
8080
)
console
.
log
(
port
)
const
app
=
express
()
app
.
use
((
req
,
res
,
done
)
=>
{
// console.log(req.headers)
t
.
is
(
req
.
headers
[
'
referer
'
],
'
https://wx.qq.com/
'
)
done
()
})
let
server
:
http
.
Server
await
new
Promise
((
resolve
,
reject
)
=>
{
server
=
app
.
listen
(
port
,
resolve
)
})
const
serverUrl
=
'
http://127.0.0.1:
'
+
port
const
options
:
url
.
Url
=
url
.
parse
(
serverUrl
)
options
[
'
headers
'
]
=
{
Accept
:
'
image/webp,image/*,*/*;q=0.8
'
,
'
User-Agent
'
:
'
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
'
,
Referer
:
'
https://wx.qq.com/
'
,
'
Accept-Encoding
'
:
'
gzip, deflate, sdch
'
,
'
Accept-Language
'
:
'
zh-CN,zh;q=0.8
'
,
}
options
[
'
agent
'
]
=
http
.
globalAgent
await
new
Promise
((
resolve
,
reject
)
=>
{
console
.
log
(
'
1
'
)
const
req
=
http
.
request
(
options
as
any
as
http
.
RequestOptions
,
(
res
)
=>
{
// console.log(`STATUS: ${res.statusCode}`);
// console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
// res.setEncoding('utf8');
console
.
log
(
'
2
'
)
t
.
pass
(
'
http.request done
'
)
req
.
on
(
'
error
'
,
reject
)
return
resolve
()
})
req
.
on
(
'
error
'
,
reject
)
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录