1 | const Page = require('./Page');
|
2 | const {helper} = require('./helper');
|
3 |
|
4 | class Target {
|
5 | |
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | constructor(targetInfo, sessionFactory, ignoreHTTPSErrors, setDefaultViewport, screenshotTaskQueue) {
|
13 | this._targetInfo = targetInfo;
|
14 | this._targetId = targetInfo.targetId;
|
15 | this._sessionFactory = sessionFactory;
|
16 | this._ignoreHTTPSErrors = ignoreHTTPSErrors;
|
17 | this._setDefaultViewport = setDefaultViewport;
|
18 | this._screenshotTaskQueue = screenshotTaskQueue;
|
19 |
|
20 | this._pagePromise = null;
|
21 | this._initializedPromise = new Promise(fulfill => this._initializedCallback = fulfill);
|
22 | this._isClosedPromise = new Promise(fulfill => this._closedCallback = fulfill);
|
23 | this._isInitialized = this._targetInfo.type !== 'page' || this._targetInfo.url !== '';
|
24 | if (this._isInitialized)
|
25 | this._initializedCallback(true);
|
26 | }
|
27 |
|
28 | |
29 |
|
30 |
|
31 | createCDPSession() {
|
32 | return this._sessionFactory();
|
33 | }
|
34 |
|
35 | |
36 |
|
37 |
|
38 | async page() {
|
39 | if (this._targetInfo.type === 'page' && !this._pagePromise) {
|
40 | this._pagePromise = this._sessionFactory()
|
41 | .then(client => Page.create(client, this, this._ignoreHTTPSErrors, this._setDefaultViewport, this._screenshotTaskQueue));
|
42 | }
|
43 | return this._pagePromise;
|
44 | }
|
45 |
|
46 | |
47 |
|
48 |
|
49 | url() {
|
50 | return this._targetInfo.url;
|
51 | }
|
52 |
|
53 | |
54 |
|
55 |
|
56 | type() {
|
57 | const type = this._targetInfo.type;
|
58 | if (type === 'page' || type === 'service_worker' || type === 'browser')
|
59 | return type;
|
60 | return 'other';
|
61 | }
|
62 |
|
63 | |
64 |
|
65 |
|
66 | _targetInfoChanged(targetInfo) {
|
67 | this._targetInfo = targetInfo;
|
68 |
|
69 | if (!this._isInitialized && (this._targetInfo.type !== 'page' || this._targetInfo.url !== '')) {
|
70 | this._isInitialized = true;
|
71 | this._initializedCallback(true);
|
72 | return;
|
73 | }
|
74 | }
|
75 | }
|
76 |
|
77 | helper.tracePublicAPI(Target);
|
78 |
|
79 | module.exports = Target; |
\ | No newline at end of file |