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

core(fetcher): remove iframe fetcher #13923

Merged
merged 15 commits into from
May 5, 2022
Merged

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Apr 27, 2022

The iframe fetcher was being used only in LR (see #13006), but now we have protocol support (originsWithUniversalNetworkAccess) to use fetch directly in LR.

Draft because we're waiting on some changes to WRS.

@connorjclark connorjclark requested a review from a team as a code owner April 27, 2022 00:02
@connorjclark connorjclark requested review from brendankenny and removed request for a team April 27, 2022 00:02
@brendankenny

This comment was marked as outdated.

return {
content,
status: response.status,
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

iframe fetcher suppressed the response content if the status code was not 2xx. (note: this was not a mistake, even if cached 304 response was received JS fetch sees the cached 2xx response code. and by default redirects are followed and the status code is the final response)

Should we consider suppressing the response content here if the status code is not 2xx (like iframe fetcher did)? And also for Network.loadNetworkResponse?

Copy link
Member

Choose a reason for hiding this comment

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

Does the browser still work with robots.txt or source maps that have a non-2xx status code?

Copy link
Collaborator Author

@connorjclark connorjclark May 4, 2022

Choose a reason for hiding this comment

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

I don't think the status code matters for source maps.

for robots.txt yes it needs to be 2xx https://developers.google.com/search/docs/advanced/robots/robots_txt#http-status-codes and the audit already checks this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should just return anything we get + the status code, and leave it to each use case to check the status if they care. we should be good as it is.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should just return anything we get + the status code, and leave it to each use case to check the status if they care. we should be good as it is.

Yeah SGTM

@connorjclark connorjclark marked this pull request as draft April 27, 2022 00:09

/** @typedef {{content: string|null, status: number|null}} FetchResponse */

const log = require('lighthouse-logger');
const {getBrowserVersion} = require('./driver/environment.js');

class Fetcher {
Copy link
Member

@adamraine adamraine Apr 27, 2022

Choose a reason for hiding this comment

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

We don't need to use a class anymore, the state is just whatever session we pass into the constructor. We could refactor this to be more function like the rest of our helper files in lighthouse-core/gather/driver. This way we don't need to pass around a fetcher object on the gather context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should do this in a different PR.

@connorjclark
Copy link
Collaborator Author

confirmed working in LR.

@connorjclark connorjclark marked this pull request as ready for review May 4, 2022 17:56
Base automatically changed from misc-smoke-byte-changes to master May 4, 2022 17:57
@@ -48,10 +48,20 @@ describe('SourceMaps gatherer', () => {
const sendCommandMock = createMockSendCommandFn()
.mockResponse('Debugger.enable', {})
.mockResponse('Debugger.disable', {})
<<<<<<< HEAD
Copy link
Member

@adamraine adamraine May 4, 2022

Choose a reason for hiding this comment

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

Why is it always merge conflict

lighthouse-core/test/gather/fetcher-test.js Show resolved Hide resolved
lighthouse-core/test/gather/gatherers/source-maps-test.js Outdated Show resolved Hide resolved
/** @type {{stream: LH.Crdp.IO.StreamHandle|null, status: number|null}} */
const response = await Promise.race([responsePromise, timeoutPromise])
.finally(() => clearTimeout(timeoutHandle));
const response = await this._wrapWithTimeout(this._loadNetworkResource(url), options.timeout);
Copy link
Member

Choose a reason for hiding this comment

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

_readIOStream has its own weird timeout system, would it be possible to remove that and use _wrapWithTimeout over _fetchResourceOverProtocol?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it wouldn't be the same, unless we made the work _readIOStream does use a cancel-able promise. even if the wrapped timer timed out the work would keep going

return {
content,
status: response.status,
};
Copy link
Member

Choose a reason for hiding this comment

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

Does the browser still work with robots.txt or source maps that have a non-2xx status code?

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

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

LGTM, only thing left would be not fetch content for non-2xx responses in the protocol fetcher.

@connorjclark connorjclark merged commit 54a1e04 into master May 5, 2022
@connorjclark connorjclark deleted the lr-no-iframe-fetcher branch May 5, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants