Changed export code to (hopefully) support larger exports
Brian Vaughn committed
May 22, 2019 at 08:41 UTC
d1344768b205de590531c5e8cbec991d304958d0
1 file changed
+13
-5
src/devtools/views/utils.js
+13
-5
@@ -147,14 +147,22 @@ export function serializeHooksForCopy(hooks: HooksTree | null): string {
147
}
148
}
149
150
+// Keeping this in memory seems to be enough to enable the browser to download larger profiles.
151
+// Without this, we would see a "Download failed: network error" failure.
152
+let downloadUrl = null;
153
+
154
export function downloadFile(filename: string, text: string): void {
155
+ const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
156
+
157
+ if (downloadUrl !== null) {
158
+ URL.revokeObjectURL(downloadUrl);
159
+ }
160
+
161
+ downloadUrl = URL.createObjectURL(blob);
162
+
163
const element = document.createElement('a');
152
- element.setAttribute(
153
- 'href',
154
- 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)
155
- );
164
+ element.setAttribute('href', downloadUrl);
165
element.setAttribute('download', filename);
157
-
166
element.style.display = 'none';
167
((document.body: any): HTMLBodyElement).appendChild(element);
168