nodejs_chromium 1.0.2 → 1.0.3
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 +21 -16
package/package.json
CHANGED
package/src/chrome.js
CHANGED
|
@@ -45,10 +45,6 @@ module.exports = class {
|
|
|
45
45
|
this.responseCall = call;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
async setCookie(cookies) {
|
|
49
|
-
await this.page.setCookie(...cookies);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
48
|
async open(url) {
|
|
53
49
|
await this.page.goto(url, { waitUntil: 'load' });
|
|
54
50
|
}
|
|
@@ -74,9 +70,6 @@ module.exports = class {
|
|
|
74
70
|
|
|
75
71
|
/**
|
|
76
72
|
* page.on方法
|
|
77
|
-
*
|
|
78
|
-
* @param {Object} key
|
|
79
|
-
* @param {Object} call
|
|
80
73
|
*/
|
|
81
74
|
async on(key, call) {
|
|
82
75
|
await this.page.on(key, call);
|
|
@@ -86,14 +79,21 @@ module.exports = class {
|
|
|
86
79
|
await this.browser.disconnect();
|
|
87
80
|
}
|
|
88
81
|
|
|
89
|
-
async
|
|
90
|
-
if (
|
|
91
|
-
|
|
82
|
+
async navigation(timeout = 0, tryCount = 0) {
|
|
83
|
+
if (timeout < 200) timeout = timeout * 1000;
|
|
84
|
+
try {
|
|
85
|
+
await this.page.waitForNavigation({ timeout });
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
if (tryCount > 0) {
|
|
90
|
+
return await this.navigation(ele, timeout, --tryCount)
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
92
93
|
}
|
|
93
|
-
await this.page.waitForNavigation();
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async
|
|
96
|
+
async wait(ele, timeout = 0, tryCount = 0) {
|
|
97
97
|
if (timeout < 200) timeout = timeout * 1000;
|
|
98
98
|
try {
|
|
99
99
|
await this.page.waitForSelector(ele, { timeout });
|
|
@@ -101,7 +101,7 @@ module.exports = class {
|
|
|
101
101
|
}
|
|
102
102
|
catch (e) {
|
|
103
103
|
if (tryCount > 0) {
|
|
104
|
-
return await this.
|
|
104
|
+
return await this.wait(ele, timeout, --tryCount)
|
|
105
105
|
}
|
|
106
106
|
return false;
|
|
107
107
|
}
|
|
@@ -120,6 +120,14 @@ module.exports = class {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
async setCookie(cookies) {
|
|
124
|
+
await this.page.setCookie(...cookies);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async getCookie() {
|
|
128
|
+
return await this.page.cookies();
|
|
129
|
+
}
|
|
130
|
+
|
|
123
131
|
async saveCookies(file) {
|
|
124
132
|
try {
|
|
125
133
|
const cookies = await this.page.cookies();
|
|
@@ -153,7 +161,6 @@ module.exports = class {
|
|
|
153
161
|
* 网页拍照
|
|
154
162
|
* @param file
|
|
155
163
|
* @param quality
|
|
156
|
-
* @returns {Promise<void>}
|
|
157
164
|
*/
|
|
158
165
|
async photograph(file, quality = 50) {
|
|
159
166
|
await this.page.screenshot({
|
|
@@ -168,8 +175,6 @@ module.exports = class {
|
|
|
168
175
|
|
|
169
176
|
/**
|
|
170
177
|
* 补全所有本地js/css
|
|
171
|
-
* @returns {Promise<void>}
|
|
172
|
-
* @constructor
|
|
173
178
|
*/
|
|
174
179
|
async improveUrls() {
|
|
175
180
|
const url = parseUrl(this.page.url());
|