Transfer Size Policy and Pause Document APIs
Why is my phone warm?
Last week a small webpage burned up 800MB ($8 on Google FI) on my wife’s phone. Presumably this wasn’t intentional.
What can we do?
Moving Forward
Let’s make it possible for the UA and developers to constrain third-party content by limiting access to the network, memory, and CPU
There are lots of ways we could do this, and here’s a start:
Transfer Size Policy - https://github.com/WICG/transfer-size
Counts the network bytes used by an iframe and its descendants
Fires a bubbling event (transferexceeded) on parent iframe element when given threshold is exceeded
The parent frame can respond however it likes:
Transfer Size Policy - https://github.com/WICG/transfer-size
This leaks size information to the embedding frame.
Transfer Size Policy - https://github.com/WICG/transfer-size
Basic detection of large iframe:
<script>� function onBigFrame(event) {� alert("Frame is too big!");� }� </script>�� <iframe id="foo" ontransferexceeded="onBigFrame(event)" transfersize="300" src="...">
Transfer Size Policy - https://github.com/WICG/transfer-size
Breakdown by resource type:
<script>� function onBigFrame(event) {� log("Frame went over its javascript budget. FIX!");� }� </script>
<iframe id="foo" ontransferexceeded="onBigFrame(event)" transfersize="script:100, total:500" src="...">
Transfer Size Policy - https://github.com/WICG/transfer-size
Can be set by headers as well:
transfersizes: {"default":"100", "self":"*", "*.example.com":"style:50, total:500"}
<script>� document.ontransferexceeded=onBigFrame;� </script>
Transfer Size Demo
Pause Document, an effective response
Want to stop a heavy frame from using more resources
But want the user to be able to resume the frame’s activity if it’s useful to them
Hence, iframe pause and unpause
* Also useful to pause off-screen frames to improve the on-screen experience
PauseDocument - https://github.com/jkarlin/pause-document
await frameElement.pause({loading: true, rendering: false, script: false});
await frameElement.unpause();
frameElement.paused();
PauseDocument - https://github.com/jkarlin/pause-document
await frameElement.pause({loading: true});�
PauseDocument - https://github.com/jkarlin/pause-document
await frameElement.pause({rendering: true});�
PauseDocument - https://github.com/jkarlin/pause-document
await frameElement.pause({script: true});�
Pause Document Demo
For future discussion
Thank you!