-
Notifications
You must be signed in to change notification settings - Fork 439
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
Waiting too long (stuck) when getting a large ArrayBuffer content with GM_xhr #279
Comments
I have encountered such a problem. |
Hi again, I'm just reply here to describe it clearly :-) As Tampermonkey also released in Edge, so I tested my script to ensure that is it supports Edge. It's a script like the script that posted here, use Test script: // ==UserScript==
// @name GM_xhr test
// @version 1.0
// @description Get a large binary file as ArrayBuffer with GM_xhr
// @include http://localhost/*
// @grant GM_xmlhttpRequest
// @connect localhost
// ==/UserScript==
// modify url and @connect if needed
var url = 'http://localhost/test.mp3';
console.log('Environment: '); // Surely, I input it by myself! :-)
GM_xmlhttpRequest({
method: 'GET',
url: url,
responseType: 'arraybuffer',
onload: function(res){
var t = new Date();
console.log('File loaded at ' + t);
console.log('Elapsed time: ' + (t - ot) + 'ms');
var response = res.response;
var t2 = new Date();
console.log('Get ArrayBuffer content at ' + t2);
console.log('File size: ' + response.byteLength);
console.log('Elapsed time: ' + (t2 - t) + ' ms');
// play music, also check if pasted time is correct
var blob = new Blob([response], {type: 'audio/mpeg'});
var blobURL = URL.createObjectURL(blob);
var audio = document.createElement('audio');
audio.src = blobURL;
audio.play();
var t3 = new Date();
console.log('Start playing at ' + t3);
console.log('Elapsed time: ' + (t3 - t) + ' ms (since file loaded)');
},
onerror: function(res){
console.log('Can\'t load file.');
}
});
var ot = new Date();
console.log('Requested at ' + ot); The file In Chrome, I tested Violent monkey, Tampermonkey Legacy and Tampermonkey BETA, their logs are showing below: It seems that after This also happens in Firefox, here are the logs of GreaseMonkey and Tampermonkey in Firefox: You can see the second request took about 30 seconds to get So it would probably because of transferring data from background page to content script, however you can still noticed that in latest Tampermonkey, it takes a lot of time to get the ArrayBuffer content after the Also the same in Edge. I opened Then half a minute later, it played the music again, and the play time was updated. I tried logging the Updated Sat, 03 Sep 2016 10:17 GMT: Added Microsoft Edge screenshot. |
Sorry for the delay. The fix required major changes that I had put off for too long. However, the issue should be fixed at TM BETA 4.12.6124. 😅 I'm not sure the Chrome Webstore team will be able to review this version this year, but in the meantime, you can download it from here. |
Not fixed. With TM BETA 4.12.6123: lags, but file is downloaded. From my issue: // ==UserScript==
// @name Issue 1107 (279) (GM.xmlHttpRequest, 104 MB, gfycat.com)
// @namespace Issues
// @match https://github.com/Tampermonkey/tampermonkey/issues/1107
// @match https://github.com/Tampermonkey/tampermonkey/issues/279
// @match https://example.com/
// @grant GM.xmlHttpRequest
// @connect giant.gfycat.com
// ==/UserScript==
!async function() {
console.log("downloading (104 MB)...");
const response = await new Promise((resolve, reject) => {
GM.xmlHttpRequest({
method: "get",
url: "https://giant.gfycat.com/ConfusedRecentGuppy.mp4", // 104 MB
// url: "https://giant.gfycat.com/ShockedSecondaryFiddlercrab.mp4", // 32 MB
responseType: "blob",
onload: resolve,
onerror: reject,
});
});
console.log("response:", response);
const {response: blob} = response;
downloadBlob(blob, "ConfusedRecentGuppy.mp4");
}();
function downloadBlob(blob, name) {
const anchor = document.createElement("a");
anchor.setAttribute("download", name || "");
anchor.href = URL.createObjectURL(blob);
anchor.click();
} |
@AlttiRi Hmm, I've double checked this with exactly this script and: Windows 10 Pro 20H2 Ubuntu 20.04 and it works all the time: the log message is printed, it takes 10 to 15 seconds and the file becomes visible as browser download. Do you see errors at the site's console or extension background page console? |
Well, it works fine from my side, got a mp4 file with 109,640,890 bytes and it matches content-length header. Maybe you can restart your browser and retry?
…---原始邮件---
发件人:"AlttiRi"<[email protected]>
发送时间:2020年12月31日 星期四 下午1:21
收件人:"Tampermonkey/tampermonkey"<[email protected]>
主题:Re: [Tampermonkey/tampermonkey] Waiting too long (stuck) when getting a large ArrayBuffer content with GM_xhr (#279)
Not fixed.
With TM BETA 4.12.6123: lags, but file is downloaded.
With TM BETA 4.12.6123: no lags, but file isnotdownloaded. At all.
Frommy issue:
// ==UserScript==//@nameIssue 1107 (GM.xmlHttpRequest, 104 MB, gfycat.com)//@namespaceIssues//@matchhttps://github.com/Tampermonkey/tampermonkey/issues/1107//@matchhttps://example.com///@grantGM.xmlHttpRequest//@connectgiant.gfycat.com// ==/UserScript==!asyncfunction(){console.log("downloading (104 MB)...");constresponse=awaitnewPromise((resolve,reject)=>{GM.xmlHttpRequest({method:"get",url:"https://giant.gfycat.com/ConfusedRecentGuppy.mp4",// 104 MBresponseType:"blob",onload:resolve,onerror:reject,});});console.log("response:",response);const{response:blob}=response;downloadBlob(blob,"ConfusedRecentGuppy.mp4");}();functiondownloadBlob(blob,name){constanchor=document.createElement("a");anchor.setAttribute("download",name||"");anchor.href=URL.createObjectURL(blob);anchor.click();}
-
You are receiving this because you authored the thread.
Reply to this email directly,view it on GitHub, orunsubscribe.
|
I get the Chrome 87.0.4280.88. Even with all extensions are disabled. It only downloads the file in the background script. |
Well, it works fine on example.com, but not here (github.com) now (due to CSP). VM works even here. The old TM version worked here too, but with bugs described earlier.
|
Yep, I changed my test script to make it runs on GitHub, and get the same CSP error. I tested it with ViolentMonkey, and it works fine, seems it bypass the CSP limit. That reminds me another userscript management extension named Guerilla Scripting that works on Pale Moon browser. Well the current version of Tampermonkey works better than that, since Guerilla Scripting doesn't solve the cross origin problem, so when you're trying to call |
I see. Thanks. |
Finally... 4.12.6125 (so at least hopefully 🙈😁) |
Tested with Chrome 89.0.4378.0 canary with Tampermonkey BETA v4.12.6125, each file from my script can be downloaded successfully, and the file hashes are matched. 🥳 |
Example script: https://gist.github.com/ccloli/9c6c6ab484cfc78bddcaf656afc6cc73
When getting a large binary file as Arraybuffer with
GM_xmlhttpRequest
, browser will stuck. I checkedres
, seems that Tampermonkey stored response data as string, and transfer it to ArrayBuffer when requestingres.response
. So if response data is too large, Tampermonkey would waste too much time and CPU resource to transfer it.Here are some screenshots of test result:
Tampermonkey on Chrome
Violentmonkey on Chrome
Tampermonkey on Firefox (however, I waited about 10 seconds until the music played)
GreaseMonkey on Firefox
The text was updated successfully, but these errors were encountered: