-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(iframe-elements): Include new IFrameElements gatherer (#8979)
- Loading branch information
1 parent
9956612
commit 5a04b17
Showing
8 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Where is my iframe?</title> | ||
</head> | ||
<body> | ||
<h1>Hello frames</h1> | ||
<iframe name="oopif" src="https://www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/" style="width: 100vw; height: 100vh;"></iframe> | ||
<iframe id="oopif" name="oopif" src="https://www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/" style="width: 100vw; height: 110vh;"></iframe> | ||
<iframe id="outer-iframe" src="http://localhost:10200/online-only.html" style="position: fixed"></iframe> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,4 @@ | |
*/ | ||
module.exports = { | ||
extends: 'lighthouse:default', | ||
settings: { | ||
onlyAudits: [ | ||
'network-requests', | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @license Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const Gatherer = require('./gatherer.js'); | ||
const pageFunctions = require('../../lib/page-functions.js'); | ||
|
||
/* eslint-env browser, node */ | ||
|
||
/** | ||
* @return {LH.Artifacts['IFrameElements']} | ||
*/ | ||
/* istanbul ignore next */ | ||
function collectIFrameElements() { | ||
// @ts-ignore - put into scope via stringification | ||
const iFrameElements = getElementsInDocument('iframe'); // eslint-disable-line no-undef | ||
return iFrameElements.map(/** @param {HTMLIFrameElement} node */ (node) => { | ||
const clientRect = node.getBoundingClientRect(); | ||
const {top, bottom, left, right, width, height} = clientRect; | ||
return { | ||
id: node.id, | ||
src: node.src, | ||
clientRect: {top, bottom, left, right, width, height}, | ||
// @ts-ignore - put into scope via stringification | ||
isPositionFixed: isPositionFixed(node), // eslint-disable-line no-undef | ||
}; | ||
}); | ||
} | ||
|
||
class IFrameElements extends Gatherer { | ||
/** | ||
* @param {LH.Gatherer.PassContext} passContext | ||
* @return {Promise<LH.Artifacts['IFrameElements']>} | ||
* @override | ||
*/ | ||
async afterPass(passContext) { | ||
const driver = passContext.driver; | ||
|
||
const expression = `(() => { | ||
${pageFunctions.getOuterHTMLSnippetString}; | ||
${pageFunctions.getElementsInDocumentString}; | ||
${pageFunctions.isPositionFixedString}; | ||
return (${collectIFrameElements})(); | ||
})()`; | ||
|
||
/** @type {LH.Artifacts['IFrameElements']} */ | ||
const iframeElements = await driver.evaluateAsync(expression, {useIsolation: true}); | ||
return iframeElements; | ||
} | ||
} | ||
|
||
module.exports = IFrameElements; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters