Skip to content

Commit ca43262

Browse files
authored
Merge pull request #1101 from prikshittekta/hc-navigation
close browser incase of errors
2 parents 5182b9e + 12752f0 commit ca43262

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

api/utils/render.js

+19-28
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ exports.renderView = function(options, cb) {
6363
});
6464
}
6565

66-
try {
67-
if (!chromePath && alternateChrome) {
68-
chromePath = yield fetchChromeExecutablePath();
69-
}
66+
if (!chromePath && alternateChrome) {
67+
chromePath = yield fetchChromeExecutablePath();
68+
}
7069

71-
var settings = {
72-
headless: true,
73-
args: ['--no-sandbox', '--disable-setuid-sandbox'],
74-
ignoreHTTPSErrors: true,
75-
userDataDir: pathModule.resolve(__dirname, "../../dump/chrome")
76-
};
70+
var settings = {
71+
headless: true,
72+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
73+
ignoreHTTPSErrors: true,
74+
userDataDir: pathModule.resolve(__dirname, "../../dump/chrome")
75+
};
7776

78-
if (chromePath) {
79-
settings.executablePath = chromePath;
80-
}
77+
if (chromePath) {
78+
settings.executablePath = chromePath;
79+
}
8180

82-
var browser = yield puppeteer.launch(settings);
81+
var browser = yield puppeteer.launch(settings);
8382

83+
try {
8484
var page = yield browser.newPage();
8585

8686
page.on('console', (msg) => {
@@ -112,7 +112,7 @@ exports.renderView = function(options, cb) {
112112
var cbFn = options.cbFn || function() {};
113113
var beforeScrnCbFn = options.beforeScrnCbFn || function() {};
114114
var source = options.source;
115-
var navigationTimeout = options.timeout || 30000;
115+
var updatedTimeout = options.timeout || 30000;
116116

117117
options.dimensions = {
118118
width: options.dimensions && options.dimensions.width ? options.dimensions.width : 1366,
@@ -121,27 +121,17 @@ exports.renderView = function(options, cb) {
121121
scale: options.dimensions && options.dimensions.scale ? options.dimensions.scale : 2
122122
};
123123

124-
page.setDefaultNavigationTimeout(navigationTimeout);
124+
page.setDefaultNavigationTimeout(updatedTimeout);
125125

126126
yield page.goto(host + '/login/token/' + token + '?ssr=true');
127127

128-
try {
129-
yield page.waitForSelector('countly');
130-
}
131-
catch (e) {
132-
//Wait time exceeded
133-
}
128+
yield page.waitForSelector('countly', {timeout: updatedTimeout});
134129

135130
yield timeout(2000);
136131

137132
yield page.goto(host + view);
138133

139-
try {
140-
yield page.waitForSelector('countly');
141-
}
142-
catch (e) {
143-
//Wait time exceeded
144-
}
134+
yield page.waitForSelector('countly', {timeout: updatedTimeout});
145135

146136
yield timeout(10000);
147137

@@ -225,6 +215,7 @@ exports.renderView = function(options, cb) {
225215
}
226216
catch (e) {
227217
log.e(e, e.stack);
218+
yield browser.close();
228219
throw e;
229220
}
230221
})().then(function(response) {

0 commit comments

Comments
 (0)