nodejs_chromium 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/chrome.js +24 -14
package/package.json
CHANGED
package/src/chrome.js
CHANGED
|
@@ -45,8 +45,9 @@ module.exports = class {
|
|
|
45
45
|
this.responseCall = call;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
async
|
|
49
|
-
|
|
48
|
+
async waiting(time) {
|
|
49
|
+
if (time < 100) time = time * 1000;
|
|
50
|
+
return await new Promise(res => setTimeout(res, time));
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
async open(url) {
|
|
@@ -74,9 +75,6 @@ module.exports = class {
|
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
77
|
* page.on方法
|
|
77
|
-
*
|
|
78
|
-
* @param {Object} key
|
|
79
|
-
* @param {Object} call
|
|
80
78
|
*/
|
|
81
79
|
async on(key, call) {
|
|
82
80
|
await this.page.on(key, call);
|
|
@@ -86,14 +84,21 @@ module.exports = class {
|
|
|
86
84
|
await this.browser.disconnect();
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
async
|
|
90
|
-
if (
|
|
91
|
-
|
|
87
|
+
async navigation(timeout = 0, tryCount = 0) {
|
|
88
|
+
if (timeout < 200) timeout = timeout * 1000;
|
|
89
|
+
try {
|
|
90
|
+
await this.page.waitForNavigation({ timeout });
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
if (tryCount > 0) {
|
|
95
|
+
return await this.navigation(ele, timeout, --tryCount)
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
92
98
|
}
|
|
93
|
-
await this.page.waitForNavigation();
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
async
|
|
101
|
+
async wait(ele, timeout = 0, tryCount = 0) {
|
|
97
102
|
if (timeout < 200) timeout = timeout * 1000;
|
|
98
103
|
try {
|
|
99
104
|
await this.page.waitForSelector(ele, { timeout });
|
|
@@ -101,7 +106,7 @@ module.exports = class {
|
|
|
101
106
|
}
|
|
102
107
|
catch (e) {
|
|
103
108
|
if (tryCount > 0) {
|
|
104
|
-
return await this.
|
|
109
|
+
return await this.wait(ele, timeout, --tryCount)
|
|
105
110
|
}
|
|
106
111
|
return false;
|
|
107
112
|
}
|
|
@@ -120,6 +125,14 @@ module.exports = class {
|
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
|
|
128
|
+
async setCookie(cookies) {
|
|
129
|
+
await this.page.setCookie(...cookies);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async getCookie() {
|
|
133
|
+
return await this.page.cookies();
|
|
134
|
+
}
|
|
135
|
+
|
|
123
136
|
async saveCookies(file) {
|
|
124
137
|
try {
|
|
125
138
|
const cookies = await this.page.cookies();
|
|
@@ -153,7 +166,6 @@ module.exports = class {
|
|
|
153
166
|
* 网页拍照
|
|
154
167
|
* @param file
|
|
155
168
|
* @param quality
|
|
156
|
-
* @returns {Promise<void>}
|
|
157
169
|
*/
|
|
158
170
|
async photograph(file, quality = 50) {
|
|
159
171
|
await this.page.screenshot({
|
|
@@ -168,8 +180,6 @@ module.exports = class {
|
|
|
168
180
|
|
|
169
181
|
/**
|
|
170
182
|
* 补全所有本地js/css
|
|
171
|
-
* @returns {Promise<void>}
|
|
172
|
-
* @constructor
|
|
173
183
|
*/
|
|
174
184
|
async improveUrls() {
|
|
175
185
|
const url = parseUrl(this.page.url());
|