|
|
@@ -29,8 +29,6 @@ const { JSDOM, VirtualConsole } = require("jsdom");
|
|
|
const iconv = require("iconv-lite");
|
|
|
const request = require("request-promise-native");
|
|
|
|
|
|
-let win;
|
|
|
-
|
|
|
exports.initialize = async () => { };
|
|
|
|
|
|
exports.getPageData = async options => {
|
|
|
@@ -43,9 +41,16 @@ exports.getPageData = async options => {
|
|
|
"User-Agent": options.userAgent
|
|
|
}
|
|
|
})).body.toString();
|
|
|
- const dom = new JSDOM(pageContent, getBrowserOptions(options));
|
|
|
- win = dom.window;
|
|
|
- return await getPageData(win, options);
|
|
|
+ let win;
|
|
|
+ try {
|
|
|
+ const dom = new JSDOM(pageContent, getBrowserOptions(options));
|
|
|
+ win = dom.window;
|
|
|
+ return await getPageData(win, options);
|
|
|
+ } finally {
|
|
|
+ if (win) {
|
|
|
+ win.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
async function getPageData(win, options) {
|
|
|
@@ -83,11 +88,7 @@ async function getPageData(win, options) {
|
|
|
return pageData;
|
|
|
}
|
|
|
|
|
|
-exports.closeBrowser = () => {
|
|
|
- if (win) {
|
|
|
- win.close();
|
|
|
- }
|
|
|
-};
|
|
|
+exports.closeBrowser = () => { };
|
|
|
|
|
|
function getBrowserOptions(options) {
|
|
|
const jsdomOptions = {
|