[web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
Very simple tweak to flutter.js that allows blob URLs to be used as entrypointUrls when loading flutter (this is needed by dartpad)
## Testing
I had to test this locally by spinning up a flutter app with something like:
```html
<script>
let initSrc = `let actualMain = document.createElement("script");
document.head.appendChild(actualMain);
actualMain.id = "injected_from_a_blob";
actualMain.src = "main.dart.js";`;
let blobInit = new Blob([...initSrc]);
let blobUrl = URL.createObjectURL(blobInit);
</script>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
entrypointUrl: blobUrl,
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.autoStart();
}
});
});
</script>
```
## Issues
* Fixes https://github.com/flutter/flutter/issues/141329
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -20,6 +20,11 @@ export class FlutterTrustedTypesPolicy {
|
||||
if (window.trustedTypes) {
|
||||
this.policy = trustedTypes.createPolicy(policyName, {
|
||||
createScriptURL: function (url) {
|
||||
// Return blob urls without manipulating them
|
||||
if (url.startsWith('blob:')) {
|
||||
return url;
|
||||
}
|
||||
// Validate other urls
|
||||
const parsed = new URL(url, window.location);
|
||||
const file = parsed.pathname.split("/").pop();
|
||||
const matches = patterns.some((pattern) => pattern.test(file));
|
||||
|
||||
Reference in New Issue
Block a user