Closed nkapov closed 7 years ago
That network call is made when getHAR()
is called, which is the way of the main process to communicate with the devtools and let it know that it requires the HAR data. The script shouldn't hang, so I expect it's not ending correctly.
Can you please add more details about how are using it?
here’s a code snippet…
var browser = Nightmare(Object.assign( harPlugin.getDevtoolsOptions(), { waitTimeout: 2 60 1000, gotoTimeout: 2 60 1000, show: true, enableLargerThanScreen: true, webPreferences: { partition: topic.name, }, maxWidth: SCREEN_WIDTH + 1000, maxHeight: SCREEN_HEIGHT + 1000, } )).viewport(SCREEN_WIDTH, SCREEN_HEIGHT)
browser.useragent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
browser.name = topic.name;
browser.topic_path = path.join(sessionPath, topic.path);
browser.log = (...args) => console.log(`[${browser.name}]:, ...args); browser.__log(
browser instance created with dimensions of ${chalk.magenta.bold(SCREEN_WIDTH)}x${chalk.magenta.bold(SCREEN_HEIGHT)}`);
Function that makes the getHar call....
const capturePages = async (browser, urls, persistPath) => {
browser.log(capturing ${chalk.magenta.bold(urls.length)} pages:
);
await async.eachOfLimitAsync(
urls,
1,
async (url, index) => {
browser.log(opening url (${chalk.magenta.bold(index + 1)} of ${chalk.magenta.bold(urls.length)}):
, url);
const currentUrl = browser.url();
try {
if (currentUrl === browser.url) {
browser.log('refreshing');
await browser.refresh();
} else {
await browser.goto(url);
}
} catch (e) {
if (e.code === -3) {
browser.log(chalk.gray(navigation error on ${url}. Situation (probably) normal
));
} else {
browser.log(e);
}
}
browser.log('waiting for', PAGE_LOAD_WAIT_MS, 'ms');
await browser.wait(PAGE_LOAD_WAIT_MS);
browser.__log('saving screenshot');
await screenshotPage(browser, `${persistPath}/screenshots/${index}_${sanitizeFilename(url)}.png`);
browser.__log('saving network reqeusts as HAR');
const har = await browser.getHAR();
fs.writeFileSync(${persistPath}/network/${index}_${sanitizeFilename(url)}.har
, JSON.stringify(har, null, ' '));
browser.__log('saving cookies');
const cookies = await browser.cookies.get({ url: null });
const cookiesCSV = json2csv({ data: cookies });
fs.writeFileSync(`${persistPath}/cookies/${index}_${sanitizeFilename(url)}.json`, JSON.stringify(cookies, null, ' '));
fs.writeFileSync(`${persistPath}/cookies/${index}_${sanitizeFilename(url)}.csv`, cookiesCSV);
}
) browser.__log(chalk.green.bold('done capturing pages')); }
On May 29, 2017, at 3:13 PM, Alexandru Bardaș notifications@github.com wrote:
That network call is made when getHAR() is called, which is the way of the main process to communicate with the devtools and let it know that it requires the HAR data. The script shouldn't hang, so I expect it's not ending correctly.
Can you please add more details about how are using it?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alexbardas/nightmare-har-plugin/issues/4#issuecomment-304717449, or mute the thread https://github.com/notifications/unsubscribe-auth/ADJQQ5U7_CDw4nodhaRVP1R_bXOmYEReks5r-xjggaJpZM4NpjXX.
Not sure what resolved the issue reported - did a fresh npm install and the script no longer freezes on the Not allowed to load local resource: chrome://version/?get-har message
This specific issue is still happening for me even after another npm install. Using this for testing:
import { expect } from 'chai';
import Nightmare from 'nightmare';
import harPlugin from 'nightmare-har-plugin'
import { global } from './config';
let nightmare;
harPlugin.install(Nightmare);
const { defaultTimeout } = global;
describe('Base tests', function () {
this.timeout(defaultTimeout);
const options = {
waitTimeout: defaultTimeout
}
nightmare = Nightmare(Object.assign(harPlugin.getDevtoolsOptions(), options));
console.log(`url: ${baseURL}`);
console.log(`options: ${JSON.stringify(options)}`);
it("Page loads without error", function (done) {
nightmare
.waitForDevtools()
.goto('http://localhost:3000')
.wait('body')
.getHAR()
.end()
.then(result => {
console.log(JSON.stringify({log: result}));
expect(result).to.exist;
done();
})
.catch(done);
});
});
I see this in the console when the getHar() call is made.. Not allowed to load local resource: chrome://version/?get-har and the script hangs.