apify 2.3.1-beta.4 → 3.0.0-alpha.0
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/README.md +6 -5
- package/package.json +69 -128
- package/build/actor.d.ts +0 -113
- package/build/actor.d.ts.map +0 -1
- package/build/actor.js +0 -582
- package/build/actor.js.map +0 -1
- package/build/apify.d.ts +0 -752
- package/build/apify.d.ts.map +0 -1
- package/build/apify.js +0 -877
- package/build/apify.js.map +0 -1
- package/build/autoscaling/autoscaled_pool.d.ts +0 -384
- package/build/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/build/autoscaling/autoscaled_pool.js +0 -557
- package/build/autoscaling/autoscaled_pool.js.map +0 -1
- package/build/autoscaling/snapshotter.d.ts +0 -278
- package/build/autoscaling/snapshotter.d.ts.map +0 -1
- package/build/autoscaling/snapshotter.js +0 -447
- package/build/autoscaling/snapshotter.js.map +0 -1
- package/build/autoscaling/system_status.d.ts +0 -224
- package/build/autoscaling/system_status.d.ts.map +0 -1
- package/build/autoscaling/system_status.js +0 -228
- package/build/autoscaling/system_status.js.map +0 -1
- package/build/browser_launchers/browser_launcher.d.ts +0 -154
- package/build/browser_launchers/browser_launcher.d.ts.map +0 -1
- package/build/browser_launchers/browser_launcher.js +0 -160
- package/build/browser_launchers/browser_launcher.js.map +0 -1
- package/build/browser_launchers/browser_plugin.d.ts +0 -23
- package/build/browser_launchers/browser_plugin.d.ts.map +0 -1
- package/build/browser_launchers/browser_plugin.js +0 -25
- package/build/browser_launchers/browser_plugin.js.map +0 -1
- package/build/browser_launchers/playwright_launcher.d.ts +0 -131
- package/build/browser_launchers/playwright_launcher.d.ts.map +0 -1
- package/build/browser_launchers/playwright_launcher.js +0 -150
- package/build/browser_launchers/playwright_launcher.js.map +0 -1
- package/build/browser_launchers/puppeteer_launcher.d.ts +0 -153
- package/build/browser_launchers/puppeteer_launcher.d.ts.map +0 -1
- package/build/browser_launchers/puppeteer_launcher.js +0 -197
- package/build/browser_launchers/puppeteer_launcher.js.map +0 -1
- package/build/cache_container.d.ts +0 -31
- package/build/cache_container.d.ts.map +0 -1
- package/build/cache_container.js +0 -48
- package/build/cache_container.js.map +0 -1
- package/build/configuration.d.ts +0 -226
- package/build/configuration.d.ts.map +0 -1
- package/build/configuration.js +0 -325
- package/build/configuration.js.map +0 -1
- package/build/constants.d.ts +0 -37
- package/build/constants.d.ts.map +0 -1
- package/build/constants.js +0 -41
- package/build/constants.js.map +0 -1
- package/build/crawlers/basic_crawler.d.ts +0 -443
- package/build/crawlers/basic_crawler.d.ts.map +0 -1
- package/build/crawlers/basic_crawler.js +0 -664
- package/build/crawlers/basic_crawler.js.map +0 -1
- package/build/crawlers/browser_crawler.d.ts +0 -512
- package/build/crawlers/browser_crawler.d.ts.map +0 -1
- package/build/crawlers/browser_crawler.js +0 -540
- package/build/crawlers/browser_crawler.js.map +0 -1
- package/build/crawlers/cheerio_crawler.d.ts +0 -931
- package/build/crawlers/cheerio_crawler.d.ts.map +0 -1
- package/build/crawlers/cheerio_crawler.js +0 -913
- package/build/crawlers/cheerio_crawler.js.map +0 -1
- package/build/crawlers/crawler_extension.d.ts +0 -10
- package/build/crawlers/crawler_extension.d.ts.map +0 -1
- package/build/crawlers/crawler_extension.js +0 -19
- package/build/crawlers/crawler_extension.js.map +0 -1
- package/build/crawlers/crawler_utils.d.ts +0 -34
- package/build/crawlers/crawler_utils.d.ts.map +0 -1
- package/build/crawlers/crawler_utils.js +0 -87
- package/build/crawlers/crawler_utils.js.map +0 -1
- package/build/crawlers/playwright_crawler.d.ts +0 -448
- package/build/crawlers/playwright_crawler.d.ts.map +0 -1
- package/build/crawlers/playwright_crawler.js +0 -299
- package/build/crawlers/playwright_crawler.js.map +0 -1
- package/build/crawlers/puppeteer_crawler.d.ts +0 -425
- package/build/crawlers/puppeteer_crawler.d.ts.map +0 -1
- package/build/crawlers/puppeteer_crawler.js +0 -299
- package/build/crawlers/puppeteer_crawler.js.map +0 -1
- package/build/crawlers/statistics.d.ts +0 -185
- package/build/crawlers/statistics.d.ts.map +0 -1
- package/build/crawlers/statistics.js +0 -331
- package/build/crawlers/statistics.js.map +0 -1
- package/build/enqueue_links/click_elements.d.ts +0 -179
- package/build/enqueue_links/click_elements.d.ts.map +0 -1
- package/build/enqueue_links/click_elements.js +0 -434
- package/build/enqueue_links/click_elements.js.map +0 -1
- package/build/enqueue_links/enqueue_links.d.ts +0 -117
- package/build/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/build/enqueue_links/enqueue_links.js +0 -163
- package/build/enqueue_links/enqueue_links.js.map +0 -1
- package/build/enqueue_links/shared.d.ts +0 -42
- package/build/enqueue_links/shared.d.ts.map +0 -1
- package/build/enqueue_links/shared.js +0 -121
- package/build/enqueue_links/shared.js.map +0 -1
- package/build/errors.d.ts +0 -29
- package/build/errors.d.ts.map +0 -1
- package/build/errors.js +0 -38
- package/build/errors.js.map +0 -1
- package/build/events.d.ts +0 -11
- package/build/events.d.ts.map +0 -1
- package/build/events.js +0 -147
- package/build/events.js.map +0 -1
- package/build/index.d.ts +0 -4
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -7
- package/build/index.js.map +0 -1
- package/build/main.d.ts +0 -179
- package/build/main.d.ts.map +0 -1
- package/build/main.js +0 -81
- package/build/main.js.map +0 -1
- package/build/playwright_utils.d.ts +0 -9
- package/build/playwright_utils.d.ts.map +0 -1
- package/build/playwright_utils.js +0 -90
- package/build/playwright_utils.js.map +0 -1
- package/build/proxy_configuration.d.ts +0 -411
- package/build/proxy_configuration.d.ts.map +0 -1
- package/build/proxy_configuration.js +0 -517
- package/build/proxy_configuration.js.map +0 -1
- package/build/pseudo_url.d.ts +0 -86
- package/build/pseudo_url.d.ts.map +0 -1
- package/build/pseudo_url.js +0 -153
- package/build/pseudo_url.js.map +0 -1
- package/build/puppeteer_request_interception.d.ts +0 -8
- package/build/puppeteer_request_interception.d.ts.map +0 -1
- package/build/puppeteer_request_interception.js +0 -235
- package/build/puppeteer_request_interception.js.map +0 -1
- package/build/puppeteer_utils.d.ts +0 -250
- package/build/puppeteer_utils.d.ts.map +0 -1
- package/build/puppeteer_utils.js +0 -551
- package/build/puppeteer_utils.js.map +0 -1
- package/build/request.d.ts +0 -180
- package/build/request.d.ts.map +0 -1
- package/build/request.js +0 -261
- package/build/request.js.map +0 -1
- package/build/request_list.d.ts +0 -581
- package/build/request_list.d.ts.map +0 -1
- package/build/request_list.js +0 -826
- package/build/request_list.js.map +0 -1
- package/build/serialization.d.ts +0 -5
- package/build/serialization.d.ts.map +0 -1
- package/build/serialization.js +0 -139
- package/build/serialization.js.map +0 -1
- package/build/session_pool/errors.d.ts +0 -11
- package/build/session_pool/errors.d.ts.map +0 -1
- package/build/session_pool/errors.js +0 -18
- package/build/session_pool/errors.js.map +0 -1
- package/build/session_pool/events.d.ts +0 -5
- package/build/session_pool/events.d.ts.map +0 -1
- package/build/session_pool/events.js +0 -6
- package/build/session_pool/events.js.map +0 -1
- package/build/session_pool/session.d.ts +0 -286
- package/build/session_pool/session.d.ts.map +0 -1
- package/build/session_pool/session.js +0 -355
- package/build/session_pool/session.js.map +0 -1
- package/build/session_pool/session_pool.d.ts +0 -280
- package/build/session_pool/session_pool.d.ts.map +0 -1
- package/build/session_pool/session_pool.js +0 -393
- package/build/session_pool/session_pool.js.map +0 -1
- package/build/session_pool/session_utils.d.ts +0 -4
- package/build/session_pool/session_utils.d.ts.map +0 -1
- package/build/session_pool/session_utils.js +0 -24
- package/build/session_pool/session_utils.js.map +0 -1
- package/build/stealth/hiding_tricks.d.ts +0 -22
- package/build/stealth/hiding_tricks.d.ts.map +0 -1
- package/build/stealth/hiding_tricks.js +0 -308
- package/build/stealth/hiding_tricks.js.map +0 -1
- package/build/stealth/stealth.d.ts +0 -56
- package/build/stealth/stealth.d.ts.map +0 -1
- package/build/stealth/stealth.js +0 -125
- package/build/stealth/stealth.js.map +0 -1
- package/build/storages/dataset.d.ts +0 -288
- package/build/storages/dataset.d.ts.map +0 -1
- package/build/storages/dataset.js +0 -480
- package/build/storages/dataset.js.map +0 -1
- package/build/storages/key_value_store.d.ts +0 -243
- package/build/storages/key_value_store.d.ts.map +0 -1
- package/build/storages/key_value_store.js +0 -462
- package/build/storages/key_value_store.js.map +0 -1
- package/build/storages/request_queue.d.ts +0 -318
- package/build/storages/request_queue.d.ts.map +0 -1
- package/build/storages/request_queue.js +0 -636
- package/build/storages/request_queue.js.map +0 -1
- package/build/storages/storage_manager.d.ts +0 -87
- package/build/storages/storage_manager.d.ts.map +0 -1
- package/build/storages/storage_manager.js +0 -150
- package/build/storages/storage_manager.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- package/build/typedefs.d.ts +0 -146
- package/build/typedefs.d.ts.map +0 -1
- package/build/typedefs.js +0 -88
- package/build/typedefs.js.map +0 -1
- package/build/utils.d.ts +0 -175
- package/build/utils.d.ts.map +0 -1
- package/build/utils.js +0 -731
- package/build/utils.js.map +0 -1
- package/build/utils_log.d.ts +0 -41
- package/build/utils_log.d.ts.map +0 -1
- package/build/utils_log.js +0 -192
- package/build/utils_log.js.map +0 -1
- package/build/utils_request.d.ts +0 -77
- package/build/utils_request.d.ts.map +0 -1
- package/build/utils_request.js +0 -385
- package/build/utils_request.js.map +0 -1
- package/build/utils_social.d.ts +0 -210
- package/build/utils_social.d.ts.map +0 -1
- package/build/utils_social.js +0 -787
- package/build/utils_social.js.map +0 -1
- package/build/validators.d.ts +0 -23
- package/build/validators.d.ts.map +0 -1
- package/build/validators.js +0 -29
- package/build/validators.js.map +0 -1
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.openSessionPool = exports.SessionPool = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const events_1 = require("events");
|
|
6
|
-
const ow_1 = (0, tslib_1.__importDefault)(require("ow"));
|
|
7
|
-
const key_value_store_1 = require("../storages/key_value_store");
|
|
8
|
-
const session_1 = require("./session"); // eslint-disable-line no-unused-vars,import/named,import/no-cycle
|
|
9
|
-
const events_2 = (0, tslib_1.__importDefault)(require("../events"));
|
|
10
|
-
const utils_log_1 = (0, tslib_1.__importDefault)(require("../utils_log"));
|
|
11
|
-
const constants_1 = require("../constants");
|
|
12
|
-
const configuration_1 = require("../configuration");
|
|
13
|
-
/**
|
|
14
|
-
* Factory user-function which creates customized {@link Session} instances.
|
|
15
|
-
* @callback CreateSession
|
|
16
|
-
* @param {SessionPool} sessionPool Pool requesting the new session.
|
|
17
|
-
* @returns {Promise<Session>}
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* @typedef SessionPoolOptions
|
|
21
|
-
* @property {number} [maxPoolSize=1000] - Maximum size of the pool.
|
|
22
|
-
* Indicates how many sessions are rotated.
|
|
23
|
-
* @property {SessionOptions} [sessionOptions] The configuration options for {@link Session} instances.
|
|
24
|
-
* @property {string} [persistStateKeyValueStoreId] - Name or Id of `KeyValueStore` where is the `SessionPool` state stored.
|
|
25
|
-
* @property {string} [persistStateKey="SESSION_POOL_STATE"] - Session pool persists it's state under this key in Key value store.
|
|
26
|
-
* @property {CreateSession} [createSessionFunction] - Custom function that should return `Session` instance.
|
|
27
|
-
* Any error thrown from this function will terminate the process.
|
|
28
|
-
* Function receives `SessionPool` instance as a parameter
|
|
29
|
-
* @property {boolean} [forceCloud=false] If set to `true` then the function uses cloud storage usage even if the `APIFY_LOCAL_STORAGE_DIR`
|
|
30
|
-
* environment variable is set. This way it is possible to combine local and cloud storage.
|
|
31
|
-
*
|
|
32
|
-
* **Note:** If you use `forceCloud`, it is recommended to also set the `persistStateKeyValueStoreId` option, as otherwise the
|
|
33
|
-
* `KeyValueStore` will be unnamed!
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* Handles the rotation, creation and persistence of user-like sessions.
|
|
37
|
-
* Creates a pool of {@link Session} instances, that are randomly rotated.
|
|
38
|
-
* When some session is marked as blocked, it is removed and new one is created instead (the pool never returns an unusable session).
|
|
39
|
-
* Learn more in the [`Session management guide`](../guides/session-management).
|
|
40
|
-
*
|
|
41
|
-
* You can create one by calling the {@link Apify.openSessionPool} function.
|
|
42
|
-
*
|
|
43
|
-
* Session pool is already integrated into crawlers, and it can significantly improve your scraper
|
|
44
|
-
* performance with just 2 lines of code.
|
|
45
|
-
*
|
|
46
|
-
* **Example usage:**
|
|
47
|
-
*
|
|
48
|
-
* ```javascript
|
|
49
|
-
* const crawler = new Apify.CheerioCrawler({
|
|
50
|
-
* useSessionPool: true,
|
|
51
|
-
* persistCookiesPerSession: true,
|
|
52
|
-
* // ...
|
|
53
|
-
* })
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* You can configure the pool with many options. See the {@link SessionPoolOptions}.
|
|
57
|
-
* Session pool is by default persisted in default {@link KeyValueStore}.
|
|
58
|
-
* If you want to have one pool for all runs you have to specify
|
|
59
|
-
* {@link SessionPoolOptions.persistStateKeyValueStoreId}.
|
|
60
|
-
*
|
|
61
|
-
* **Advanced usage:**
|
|
62
|
-
*
|
|
63
|
-
* ```javascript
|
|
64
|
-
* const sessionPool = await Apify.openSessionPool({
|
|
65
|
-
* maxPoolSize: 25,
|
|
66
|
-
* sessionOptions:{
|
|
67
|
-
* maxAgeSecs: 10,
|
|
68
|
-
* maxUsageCount: 150, // for example when you know that the site blocks after 150 requests.
|
|
69
|
-
* },
|
|
70
|
-
* persistStateKeyValueStoreId: 'my-key-value-store-for-sessions',
|
|
71
|
-
* persistStateKey: 'my-session-pool',
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* // Get random session from the pool
|
|
75
|
-
* const session1 = await sessionPool.getSession();
|
|
76
|
-
* const session2 = await sessionPool.getSession();
|
|
77
|
-
* const session3 = await sessionPool.getSession();
|
|
78
|
-
*
|
|
79
|
-
* // Now you can mark the session either failed or successful
|
|
80
|
-
*
|
|
81
|
-
* // Marks session as bad after unsuccessful usage -> it increases error count (soft retire)
|
|
82
|
-
* session1.markBad()
|
|
83
|
-
*
|
|
84
|
-
* // Marks as successful.
|
|
85
|
-
* session2.markGood()
|
|
86
|
-
*
|
|
87
|
-
* // Retires session -> session is removed from the pool
|
|
88
|
-
* session3.retire()
|
|
89
|
-
*
|
|
90
|
-
* ```
|
|
91
|
-
* @hideconstructor
|
|
92
|
-
*/
|
|
93
|
-
class SessionPool extends events_1.EventEmitter {
|
|
94
|
-
/**
|
|
95
|
-
* Session pool configuration.
|
|
96
|
-
* @param {SessionPoolOptions} [options] All `SessionPool` configuration options.
|
|
97
|
-
* @param {Configuration} [config]
|
|
98
|
-
*/
|
|
99
|
-
constructor(options = {}, config = configuration_1.Configuration.getGlobalConfig()) {
|
|
100
|
-
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
101
|
-
maxPoolSize: ow_1.default.optional.number,
|
|
102
|
-
persistStateKeyValueStoreId: ow_1.default.optional.string,
|
|
103
|
-
persistStateKey: ow_1.default.optional.string,
|
|
104
|
-
createSessionFunction: ow_1.default.optional.function,
|
|
105
|
-
sessionOptions: ow_1.default.optional.object,
|
|
106
|
-
log: ow_1.default.optional.object,
|
|
107
|
-
forceCloud: ow_1.default.optional.boolean,
|
|
108
|
-
}));
|
|
109
|
-
const { maxPoolSize = 1000, persistStateKeyValueStoreId, persistStateKey = 'SDK_SESSION_POOL_STATE', createSessionFunction, sessionOptions = {}, log = utils_log_1.default, forceCloud = false, } = options;
|
|
110
|
-
super();
|
|
111
|
-
this.config = config;
|
|
112
|
-
this.log = log.child({ prefix: 'SessionPool' });
|
|
113
|
-
// Pool Configuration
|
|
114
|
-
this.maxPoolSize = maxPoolSize;
|
|
115
|
-
this.createSessionFunction = createSessionFunction || this._defaultCreateSessionFunction;
|
|
116
|
-
// Session configuration
|
|
117
|
-
this.sessionOptions = {
|
|
118
|
-
...sessionOptions,
|
|
119
|
-
// the log needs to propagate to createSessionFunction as in "new Session({ ...sessionPool.sessionOptions })"
|
|
120
|
-
// and can't go inside _defaultCreateSessionFunction
|
|
121
|
-
log: this.log,
|
|
122
|
-
};
|
|
123
|
-
// Session keyValueStore
|
|
124
|
-
this.persistStateKeyValueStoreId = persistStateKeyValueStoreId;
|
|
125
|
-
this.persistStateKey = persistStateKey;
|
|
126
|
-
// Operative states
|
|
127
|
-
this.keyValueStore = null;
|
|
128
|
-
/** @type {Session[]} */
|
|
129
|
-
this.sessions = [];
|
|
130
|
-
this.sessionMap = new Map();
|
|
131
|
-
/** @type {boolean} */
|
|
132
|
-
this.forceCloud = forceCloud;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Gets count of usable sessions in the pool.
|
|
136
|
-
* @return {number}
|
|
137
|
-
*/
|
|
138
|
-
get usableSessionsCount() {
|
|
139
|
-
return this.sessions.filter((session) => session.isUsable()).length;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Gets count of retired sessions in the pool.
|
|
143
|
-
* @return {number}
|
|
144
|
-
*/
|
|
145
|
-
get retiredSessionsCount() {
|
|
146
|
-
return this.sessions.filter((session) => !session.isUsable()).length;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Starts periodic state persistence and potentially loads SessionPool state from {@link KeyValueStore}.
|
|
150
|
-
* It is called automatically by the {@link Apify.openSessionPool} function.
|
|
151
|
-
*
|
|
152
|
-
* @return {Promise<void>}
|
|
153
|
-
*/
|
|
154
|
-
async initialize() {
|
|
155
|
-
this.keyValueStore = await (0, key_value_store_1.openKeyValueStore)(this.persistStateKeyValueStoreId, { config: this.config, forceCloud: this.forceCloud });
|
|
156
|
-
if (this.forceCloud && !this.persistStateKeyValueStoreId) {
|
|
157
|
-
this.log.warning(`You enabled 'forceCloud' in the session pool options but you haven't specified a 'persistStateKeyValueStoreId'!`);
|
|
158
|
-
this.log.warning(`This session pool's data has been saved in the KeyValueStore with the id: ${this.keyValueStore.id}`);
|
|
159
|
-
}
|
|
160
|
-
// in case of migration happened and SessionPool state should be restored from the keyValueStore.
|
|
161
|
-
await this._maybeLoadSessionPool();
|
|
162
|
-
this._listener = this.persistState.bind(this);
|
|
163
|
-
events_2.default.on(constants_1.ACTOR_EVENT_NAMES_EX.PERSIST_STATE, this._listener);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
|
|
167
|
-
* but this allows you to add more sessions once the max pool size is reached.
|
|
168
|
-
* This also allows you to add session with overridden session options (e.g. with specific session id).
|
|
169
|
-
* @param {Session|SessionOptions} [options] - The configuration options for the session being added to the session pool.
|
|
170
|
-
*/
|
|
171
|
-
async addSession(options = {}) {
|
|
172
|
-
this._throwIfNotInitialized();
|
|
173
|
-
const { id } = options;
|
|
174
|
-
if (id) {
|
|
175
|
-
const sessionExists = this.sessionMap.has(id);
|
|
176
|
-
if (sessionExists) {
|
|
177
|
-
throw new Error(`Cannot add session with id '${id}' as it already exists in the pool`);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (!this._hasSpaceForSession()) {
|
|
181
|
-
this._removeRetiredSessions();
|
|
182
|
-
}
|
|
183
|
-
const newSession = options instanceof session_1.Session
|
|
184
|
-
? options
|
|
185
|
-
: await this.createSessionFunction(this, { sessionOptions: options });
|
|
186
|
-
this.log.debug(`Adding new Session - ${newSession.id}`);
|
|
187
|
-
this._addSession(newSession);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Gets session.
|
|
191
|
-
* If there is space for new session, it creates and returns new session.
|
|
192
|
-
* If the session pool is full, it picks a session from the pool,
|
|
193
|
-
* If the picked session is usable it is returned, otherwise it creates and returns a new one.
|
|
194
|
-
*
|
|
195
|
-
* @param {String} [sessionId] - If provided, it returns the usable session with this id, `undefined` otherwise.
|
|
196
|
-
* @return {Promise<Session>}
|
|
197
|
-
*/
|
|
198
|
-
async getSession(sessionId) {
|
|
199
|
-
this._throwIfNotInitialized();
|
|
200
|
-
if (sessionId) {
|
|
201
|
-
const session = this.sessionMap.get(sessionId);
|
|
202
|
-
if (session && session.isUsable())
|
|
203
|
-
return session;
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (this._hasSpaceForSession()) {
|
|
207
|
-
return this._createSession();
|
|
208
|
-
}
|
|
209
|
-
const pickedSession = this._pickSession();
|
|
210
|
-
if (pickedSession.isUsable()) {
|
|
211
|
-
return pickedSession;
|
|
212
|
-
}
|
|
213
|
-
this._removeRetiredSessions();
|
|
214
|
-
return this._createSession();
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Returns an object representing the internal state of the `SessionPool` instance.
|
|
218
|
-
* Note that the object's fields can change in future releases.
|
|
219
|
-
*/
|
|
220
|
-
getState() {
|
|
221
|
-
return {
|
|
222
|
-
usableSessionsCount: this.usableSessionsCount,
|
|
223
|
-
retiredSessionsCount: this.retiredSessionsCount,
|
|
224
|
-
sessions: this.sessions.map((session) => session.getState()),
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Persists the current state of the `SessionPool` into the default {@link KeyValueStore}.
|
|
229
|
-
* The state is persisted automatically in regular intervals.
|
|
230
|
-
*
|
|
231
|
-
* @return {Promise<void>}
|
|
232
|
-
*/
|
|
233
|
-
async persistState() {
|
|
234
|
-
this.log.debug('Persisting state', {
|
|
235
|
-
persistStateKeyValueStoreId: this.persistStateKeyValueStoreId,
|
|
236
|
-
persistStateKey: this.persistStateKey,
|
|
237
|
-
});
|
|
238
|
-
await this.keyValueStore.setValue(this.persistStateKey, this.getState());
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Removes listener from `persistState` event.
|
|
242
|
-
* This function should be called after you are done with using the `SessionPool` instance.
|
|
243
|
-
*/
|
|
244
|
-
async teardown() {
|
|
245
|
-
events_2.default.removeListener(constants_1.ACTOR_EVENT_NAMES_EX.PERSIST_STATE, this._listener);
|
|
246
|
-
await this.persistState();
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* SessionPool should not work before initialization.
|
|
250
|
-
* @ignore
|
|
251
|
-
* @protected
|
|
252
|
-
* @internal
|
|
253
|
-
*/
|
|
254
|
-
_throwIfNotInitialized() {
|
|
255
|
-
if (!this._listener)
|
|
256
|
-
throw new Error('SessionPool is not initialized.');
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Removes retired `Session` instances from `SessionPool`.
|
|
260
|
-
* @ignore
|
|
261
|
-
* @protected
|
|
262
|
-
* @internal
|
|
263
|
-
*/
|
|
264
|
-
_removeRetiredSessions() {
|
|
265
|
-
this.sessions = this.sessions.filter((storedSession) => {
|
|
266
|
-
if (storedSession.isUsable())
|
|
267
|
-
return true;
|
|
268
|
-
this.sessionMap.delete(storedSession.id);
|
|
269
|
-
this.log.debug(`Removed Session - ${storedSession.id}`);
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Adds `Session` instance to `SessionPool`.
|
|
274
|
-
* @param {Session} newSession `Session` instance to be added.
|
|
275
|
-
* @ignore
|
|
276
|
-
* @protected
|
|
277
|
-
* @internal
|
|
278
|
-
*/
|
|
279
|
-
_addSession(newSession) {
|
|
280
|
-
this.sessions.push(newSession);
|
|
281
|
-
this.sessionMap.set(newSession.id, newSession);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Gets random index.
|
|
285
|
-
* @return {number}
|
|
286
|
-
* @ignore
|
|
287
|
-
* @protected
|
|
288
|
-
* @internal
|
|
289
|
-
*/
|
|
290
|
-
_getRandomIndex() {
|
|
291
|
-
return Math.floor(Math.random() * this.sessions.length);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Creates new session without any extra behavior.
|
|
295
|
-
* @param {SessionPool} sessionPool
|
|
296
|
-
* @param {Object} [options]
|
|
297
|
-
* @param {SessionOptions} [options.sessionOptions] - The configuration options for the session being created
|
|
298
|
-
* @return {Session} - New session.
|
|
299
|
-
* @ignore
|
|
300
|
-
* @protected
|
|
301
|
-
* @internal
|
|
302
|
-
*/
|
|
303
|
-
_defaultCreateSessionFunction(sessionPool, options = {}) {
|
|
304
|
-
(0, ow_1.default)(options, ow_1.default.object.exactShape({ sessionOptions: ow_1.default.optional.object }));
|
|
305
|
-
const { sessionOptions = {} } = options;
|
|
306
|
-
return new session_1.Session({
|
|
307
|
-
...this.sessionOptions,
|
|
308
|
-
...sessionOptions,
|
|
309
|
-
sessionPool,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Creates new session and adds it to the pool.
|
|
314
|
-
* @return {Promise<Session>} - Newly created `Session` instance.
|
|
315
|
-
* @ignore
|
|
316
|
-
* @protected
|
|
317
|
-
* @internal
|
|
318
|
-
*/
|
|
319
|
-
async _createSession() {
|
|
320
|
-
const newSession = await this.createSessionFunction(this);
|
|
321
|
-
this._addSession(newSession);
|
|
322
|
-
this.log.debug(`Created new Session - ${newSession.id}`);
|
|
323
|
-
return newSession;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Decides whether there is enough space for creating new session.
|
|
327
|
-
* @return {boolean}
|
|
328
|
-
* @ignore
|
|
329
|
-
* @protected
|
|
330
|
-
* @internal
|
|
331
|
-
*/
|
|
332
|
-
_hasSpaceForSession() {
|
|
333
|
-
return this.sessions.length < this.maxPoolSize;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Picks random session from the `SessionPool`.
|
|
337
|
-
* @return {Session} - Picked `Session`
|
|
338
|
-
* @ignore
|
|
339
|
-
* @protected
|
|
340
|
-
* @internal
|
|
341
|
-
*/
|
|
342
|
-
_pickSession() {
|
|
343
|
-
return this.sessions[this._getRandomIndex()]; // Or maybe we should let the developer to customize the picking algorithm
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Potentially loads `SessionPool`.
|
|
347
|
-
* If the state was persisted it loads the `SessionPool` from the persisted state.
|
|
348
|
-
* @return {Promise<void>}
|
|
349
|
-
* @ignore
|
|
350
|
-
* @protected
|
|
351
|
-
* @internal
|
|
352
|
-
*/
|
|
353
|
-
async _maybeLoadSessionPool() {
|
|
354
|
-
const loadedSessionPool = await this.keyValueStore.getValue(this.persistStateKey);
|
|
355
|
-
if (!loadedSessionPool)
|
|
356
|
-
return;
|
|
357
|
-
// Invalidate old sessions and load active sessions only
|
|
358
|
-
this.log.debug('Recreating state from KeyValueStore', {
|
|
359
|
-
persistStateKeyValueStoreId: this.persistStateKeyValueStoreId,
|
|
360
|
-
persistStateKey: this.persistStateKey,
|
|
361
|
-
});
|
|
362
|
-
for (const sessionObject of loadedSessionPool.sessions) {
|
|
363
|
-
sessionObject.sessionPool = this;
|
|
364
|
-
sessionObject.createdAt = new Date(sessionObject.createdAt);
|
|
365
|
-
sessionObject.expiresAt = new Date(sessionObject.expiresAt);
|
|
366
|
-
const recreatedSession = new session_1.Session(sessionObject);
|
|
367
|
-
if (recreatedSession.isUsable()) {
|
|
368
|
-
this._addSession(recreatedSession);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
this.log.debug(`${this.usableSessionsCount} active sessions loaded from KeyValueStore`);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
exports.SessionPool = SessionPool;
|
|
375
|
-
/**
|
|
376
|
-
* Opens a SessionPool and returns a promise resolving to an instance
|
|
377
|
-
* of the {@link SessionPool} class that is already initialized.
|
|
378
|
-
*
|
|
379
|
-
* For more details and code examples, see the {@link SessionPool} class.
|
|
380
|
-
*
|
|
381
|
-
* @param {SessionPoolOptions} sessionPoolOptions
|
|
382
|
-
* @return {Promise<SessionPool>}
|
|
383
|
-
* @memberof module:Apify
|
|
384
|
-
* @name openSessionPool
|
|
385
|
-
* @function
|
|
386
|
-
*/
|
|
387
|
-
const openSessionPool = async (sessionPoolOptions) => {
|
|
388
|
-
const sessionPool = new SessionPool(sessionPoolOptions);
|
|
389
|
-
await sessionPool.initialize();
|
|
390
|
-
return sessionPool;
|
|
391
|
-
};
|
|
392
|
-
exports.openSessionPool = openSessionPool;
|
|
393
|
-
//# sourceM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,SAAS,CAAC,CAAC;YAC5D,aAAa,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;YAC5D,MAAM,gBAAgB,GAAG,IAAI,iBAAO,CAAC,aAAa,CAAC,CAAC;YAEpD,IAAI,gBAAgB,CAAC,QAAQ,EAAE,EAAE;gBAC7B,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;aACtC;SACJ;QAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,mBAAmB,4CAA4C,CAAC,CAAC;IAC5F,CAAC;CACJ;AA1UD,kCA0UC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,eAAe,GAAG,KAAK,EAAE,kBAAkB,EAAE,EAAE;IACxD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACxD,MAAM,WAAW,CAAC,UAAU,EAAE,CAAC;IAC/B,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session_utils.d.ts","sourceRoot":"","sources":["../../src/session_pool/session_utils.js"],"names":[],"mappings":";AAYO,iDAHI,CAAC,eAAe,oBAAkB,CAAC,GAClC,SAAS,GAAC,UAAQ,CAa7B"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCookiesFromResponse = void 0;
|
|
4
|
-
/* eslint-enable no-unused-vars */
|
|
5
|
-
const tough_cookie_1 = require("tough-cookie");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
/**
|
|
8
|
-
* @param {(IncomingMessage|PuppeteerResponse)} response
|
|
9
|
-
* @return {undefined|Array<*>}
|
|
10
|
-
*/
|
|
11
|
-
const getCookiesFromResponse = (response) => {
|
|
12
|
-
const headers = typeof response.headers === 'function' ? response.headers() : response.headers;
|
|
13
|
-
const cookieHeader = headers['set-cookie'] || '';
|
|
14
|
-
try {
|
|
15
|
-
return Array.isArray(cookieHeader)
|
|
16
|
-
? cookieHeader.map((cookie) => tough_cookie_1.Cookie.parse(cookie))
|
|
17
|
-
: [tough_cookie_1.Cookie.parse(cookieHeader)];
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
throw new errors_1.CookieParseError(cookieHeader);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
exports.getCookiesFromResponse = getCookiesFromResponse;
|
|
24
|
-
//# sourceMappingURL=session_utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session_utils.js","sourceRoot":"","sources":["../../src/session_pool/session_utils.js"],"names":[],"mappings":";;;AAGA,kCAAkC;AAElC,+CAAsC;AACtC,qCAA4C;AAE5C;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,EAAE;IAC/C,MAAM,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;IAC/F,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAEjD,IAAI;QACA,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;YAC9B,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC,qBAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;KACtC;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,IAAI,yBAAgB,CAAC,YAAY,CAAC,CAAC;KAC5C;AACL,CAAC,CAAC;AAXW,QAAA,sBAAsB,0BAWjC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { addPlugins };
|
|
3
|
-
export { emulateWindowFrame };
|
|
4
|
-
export { emulateWebGL };
|
|
5
|
-
export { emulateConsoleDebug };
|
|
6
|
-
export { addLanguage };
|
|
7
|
-
export { hackPermissions };
|
|
8
|
-
export { mockChrome };
|
|
9
|
-
export { mockChromeInIframe };
|
|
10
|
-
export { mockDeviceMemory };
|
|
11
|
-
}
|
|
12
|
-
export default _default;
|
|
13
|
-
declare function addPlugins(): void;
|
|
14
|
-
declare function emulateWindowFrame(): void;
|
|
15
|
-
declare function emulateWebGL(): void;
|
|
16
|
-
declare function emulateConsoleDebug(): void;
|
|
17
|
-
declare function addLanguage(): void;
|
|
18
|
-
declare function hackPermissions(): void;
|
|
19
|
-
declare function mockChrome(): void;
|
|
20
|
-
declare function mockChromeInIframe(): void;
|
|
21
|
-
declare function mockDeviceMemory(): void;
|
|
22
|
-
//# sourceMappingURL=hiding_tricks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hiding_tricks.d.ts","sourceRoot":"","sources":["../../src/stealth/hiding_tricks.js"],"names":[],"mappings":";;;;;;;;;;;;AAwEA,oCA6LC;AAtMD,4CAOC;AA5BD,sCAmBC;AA0MD,6CAIC;AAvOD,qCAIC;AAtCD,yCAgCC;AA4OD,oCAQC;AAID,4CAkDC;AAED,0CAKC"}
|