Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve cache by using credentialless proxy #72

Merged
merged 6 commits into from
Apr 12, 2022
Merged

Conversation

szmarczak
Copy link
Contributor

@szmarczak szmarczak commented Apr 11, 2022

I need to test this first done

return [
undefined,
// eslint-disable-next-line @typescript-eslint/no-empty-function
async () => {},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty functions are still returned in order to prevent repeating ifs like

if (close) {
	await close();
}

page.once('close', async () => {
this.activePages--;

await close();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite unsafe because the page may open popups and get closed after opening them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus this can crash the entire process if close() throws for some unforeseeable reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pocesar

plus this can crash the entire process if close() throws for some unforeseeable reason

Yes, that's what we want. If it failed to close the server (which should never happen) then it leaks resources which means we want to crash.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite unsafe because the page may open popups and get closed after opening them.

Yeah, I see. But at the same time, closing those extra pages as well might be unexpected for users. Let's live with it and see if it causes any problems. The browsers have a hard kill interval anyway.

} catch (error: any) {
log.exception(error, 'Failed to close context.');
} finally {
await close();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -193,9 +193,6 @@ describe('Plugins', () => {
});

browser = await plugin.launch(context);
const argWithProxy = context.launchOptions?.args?.find((arg) => arg.includes('--proxy-server='));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These expectations have been removed because we check the end IP anyway. It should not check whether it goes through a local proxy server or not. Cache checks should be separate ones.

@szmarczak szmarczak marked this pull request as ready for review April 11, 2022 15:35
@szmarczak szmarczak requested review from B4nan and mnmkng April 11, 2022 15:35
@B4nan
Copy link
Member

B4nan commented Apr 11, 2022

looks like the tests got stuck

@szmarczak
Copy link
Contributor Author

@B4nan Jest fails to properly detect open handles (this is one of the reasons I believe we shouldn't use Jest), it hangs indefinitely and reports unreffed (!) servers. I've removed the open handles check, should exit now.

@szmarczak
Copy link
Contributor Author

Firefox crashes for some reason, dunno why. Good to merge otherwise.

// Launches unused browser just to get the browser version.
const inactiveBrowser = await this.library.launch(launchOptions);
this._browserVersion = inactiveBrowser.version();
inactiveBrowser.close().catch((error) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not awaiting here is on purpose? if so, what is the reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +1 for awaiting here but Ondra had said that we should skip this so I followed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to slow down just to make the version work. Nothing more really.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could use CDP for this https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-getVersion but IIRC we cannot connect to CDP with persistent context, that's a playwright limitation.

microsoft/playwright#13111

page.once('close', async () => {
this.activePages--;

await close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite unsafe because the page may open popups and get closed after opening them.

Yeah, I see. But at the same time, closing those extra pages as well might be unexpected for users. Let's live with it and see if it causes any problems. The browsers have a hard kill interval anyway.

@szmarczak
Copy link
Contributor Author

@mnmkng I have to head out to uni, feel free to merge this or I'll merge this tomorrow afternoon

@mnmkng mnmkng merged commit 9330fe0 into master Apr 12, 2022
@mnmkng mnmkng deleted the reanonymize branch April 12, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants