@applitools/eyes-storybook 3.53.14 → 3.54.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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/defaultConfig.js +1 -0
- package/src/eyesStorybook.js +12 -12
- package/src/initPage.js +8 -12
- package/src/utils/pageNetworkUtils.js +73 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.54.0](https://github.com/Applitools-Dev/sdk/compare/js/eyes-storybook@3.53.14...js/eyes-storybook@3.54.0) (2025-03-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* implement browser-side timeout for eyes storybook ([#2877](https://github.com/Applitools-Dev/sdk/issues/2877)) ([591d950](https://github.com/Applitools-Dev/sdk/commit/591d950154368cc64f93835586da1eef296e2d33))
|
|
9
|
+
|
|
3
10
|
## [3.53.14](https://github.com/Applitools-Dev/sdk/compare/js/eyes-storybook@3.53.13...js/eyes-storybook@3.53.14) (2025-03-30)
|
|
4
11
|
|
|
5
12
|
|
package/package.json
CHANGED
package/src/defaultConfig.js
CHANGED
package/src/eyesStorybook.js
CHANGED
|
@@ -23,6 +23,7 @@ const executeRenders = require('./executeRenders');
|
|
|
23
23
|
const {extractEnvironment} = require('./extractEnvironment');
|
|
24
24
|
const {makeCore} = require('@applitools/core');
|
|
25
25
|
const makeGetStoriesWithConfig = require('./getStoriesWithConfig');
|
|
26
|
+
const {makeNetworkUtils} = require('./utils/pageNetworkUtils');
|
|
26
27
|
|
|
27
28
|
async function eyesStorybook({
|
|
28
29
|
config,
|
|
@@ -55,22 +56,21 @@ async function eyesStorybook({
|
|
|
55
56
|
const browser = await puppeteer.launch(config.puppeteerOptions);
|
|
56
57
|
logger.log('browser launched');
|
|
57
58
|
const page = await browser.newPage();
|
|
59
|
+
|
|
60
|
+
const {startInterception} = makeNetworkUtils({
|
|
61
|
+
page,
|
|
62
|
+
logger,
|
|
63
|
+
});
|
|
58
64
|
// we send http headers here and in init page
|
|
59
65
|
if (config.puppeteerExtraHTTPHeaders) {
|
|
60
66
|
await page.setExtraHTTPHeaders(config.puppeteerExtraHTTPHeaders);
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
request.abort();
|
|
69
|
-
} else {
|
|
70
|
-
request.continue();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
68
|
+
|
|
69
|
+
await startInterception({
|
|
70
|
+
timeout: config.browserRequestsTimeout,
|
|
71
|
+
blockPatterns: config.networkBlockPatterns,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
74
|
const environment = extractEnvironment();
|
|
75
75
|
const core = await makeCore({spec, agentId, environment, logger});
|
|
76
76
|
const manager = await core.makeManager({
|
package/src/initPage.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
const {presult} = require('@applitools/functional-commons');
|
|
2
2
|
const browserLog = require('./browserLog');
|
|
3
3
|
const fakeIE = require('./fakeIE');
|
|
4
|
+
const {makeNetworkUtils} = require('./utils/pageNetworkUtils');
|
|
4
5
|
|
|
5
6
|
function makeInitPage({iframeUrl, config, browser, logger, getTransitiongIntoIE, getRenderIE}) {
|
|
7
|
+
const networkUtils = makeNetworkUtils({logger});
|
|
6
8
|
return async function initPage({pageId, pagePool}) {
|
|
7
9
|
logger.log('initializing puppeteer page number ', pageId);
|
|
8
10
|
const browserContext = await browser.createBrowserContext();
|
|
9
11
|
const page = await browserContext.newPage();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
request.abort();
|
|
17
|
-
} else {
|
|
18
|
-
request.continue();
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
12
|
+
const {startInterception} = networkUtils.extend({page, pageId});
|
|
13
|
+
|
|
14
|
+
await startInterception({
|
|
15
|
+
timeout: config.browserRequestsTimeout,
|
|
16
|
+
blockPatterns: config.networkBlockPatterns,
|
|
17
|
+
});
|
|
22
18
|
|
|
23
19
|
if (config.viewportSize) {
|
|
24
20
|
await page.setViewport(config.viewportSize);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
const {setTimeout} = require('timers/promises');
|
|
3
|
+
|
|
4
|
+
function makeBrowserNetworkPolicy({page, logger, pageId = null}) {
|
|
5
|
+
const scope = pageId ? `[page ${pageId}]` : '[master page]';
|
|
6
|
+
return {
|
|
7
|
+
extend(options) {
|
|
8
|
+
return makeBrowserNetworkPolicy({page, logger, pageId, ...options});
|
|
9
|
+
},
|
|
10
|
+
async startInterception({timeout, blockPatterns}) {
|
|
11
|
+
if (timeout || blockPatterns) {
|
|
12
|
+
const cdp = await page.target().createCDPSession();
|
|
13
|
+
|
|
14
|
+
await cdp.send('Fetch.enable');
|
|
15
|
+
await cdp.on('Fetch.requestPaused', async ({requestId, request}) => {
|
|
16
|
+
logger.log(`${scope} Request to ${request.url}`);
|
|
17
|
+
if (blockPatterns && blockPatterns.some(pattern => request.url.includes(pattern))) {
|
|
18
|
+
logger.log(`${scope} Blocking request to ${request.url}`);
|
|
19
|
+
await cdp.send('Fetch.failRequest', {requestId, errorReason: 'Blocked'});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (timeout) {
|
|
23
|
+
await Promise.race([
|
|
24
|
+
setTimeout(timeout, {action: 'abort'}),
|
|
25
|
+
fetchRequest(request)
|
|
26
|
+
.then(response => ({action: 'fulfill', response}))
|
|
27
|
+
.catch(() => ({action: 'fail'})),
|
|
28
|
+
]).then(async ({action, response}) => {
|
|
29
|
+
if (action === 'abort') {
|
|
30
|
+
logger.log(`${scope} Timeout for request to ${request.url}`);
|
|
31
|
+
await cdp.send('Fetch.failRequest', {requestId, errorReason: 'Aborted'});
|
|
32
|
+
} else if (action === 'fulfill') {
|
|
33
|
+
logger.log(`${scope} Fulfilled request to ${request.url}`);
|
|
34
|
+
const bodyBytes = await response.arrayBuffer();
|
|
35
|
+
const body = Buffer.from(bodyBytes).toString('base64');
|
|
36
|
+
const cdpResponse = {
|
|
37
|
+
requestId,
|
|
38
|
+
responseCode: response.status,
|
|
39
|
+
responseHeaders: [...response.headers.entries()].map(([name, value]) => ({
|
|
40
|
+
name,
|
|
41
|
+
value,
|
|
42
|
+
})),
|
|
43
|
+
body,
|
|
44
|
+
};
|
|
45
|
+
await cdp.send('Fetch.fulfillRequest', cdpResponse);
|
|
46
|
+
} else {
|
|
47
|
+
logger.log(`${scope} Failed request to ${request.url}`);
|
|
48
|
+
await cdp.send('Fetch.failRequest', {requestId, errorReason: 'Failed'});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
logger.log(`${scope} Not intercepting request to ${request.url}`);
|
|
53
|
+
await cdp.send('Fetch.continueRequest', {
|
|
54
|
+
requestId,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function fetchRequest(request) {
|
|
64
|
+
return fetch(request.url, {
|
|
65
|
+
method: request.method,
|
|
66
|
+
headers: request.headers,
|
|
67
|
+
body: request.postData,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
makeNetworkUtils: makeBrowserNetworkPolicy,
|
|
73
|
+
};
|