Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome 83: Cannot upload file

I've update Chrome on version 83, and some of my forms that use an "Ajax upload" component (more info below) aren't working. I've read the issues of the new version (https://developers.google.com/web/updates/2020/05/nic83) but I can't find anything related on forms, iframes, files, ajax or posts.

I'll try to post a sample on fiddler, but I want to know if somebody knows anything about it.

By other way, on other forms I've a multifile, drag&drop uploader (dropzone.js) and it's working fine, but it isn't easy to convert and I need a fast solution.

A dummy sample (I don't have any sandbox to test upload): https://jsfiddle.net/drvespa/7ue8k94r/3/

  • On Chrome 83 (I've tried on Canary 85 version too): it throws no error cause the submit of the form isn't catched by AjaxUpload component. The callback is being called before the submit is done, and the response is empty.
  • On Firefox: it throws an error cause AjaxUpload component is trying to deserialize 404 of the dummy upload page.

I post the library on https://filebin.net/8sgsmq7sh14m0qen:

/**
* Ajax upload
* Project page - http://valums.com/ajax-upload/
* Copyright (c) 2008 Andris Valums, http://valums.com
* Licensed under the MIT license (http://valums.com/mit-license/)
* Version 3.6 (26.06.2009)
*/
like image 755
Marc Avatar asked May 25 '20 15:05

Marc


2 Answers

The problem is that the library is creating an <iframe>, with an src attribute, and listens for the load event of that iframe right after it did.

/**
* Creates iframe with unique name
*/
_createIframe: function () {
    // unique name
    // We cannot use getTime, because it sometimes return
    // same value in safari :(
    var id = getUID();

    // Remove ie6 "This page contains both secure and nonsecure items" prompt 

    var iframe = toElement('<iframe src="javascript:false;" name="' + id + '" />');
    iframe.id = id;
    iframe.style.display = 'none';
    d.body.appendChild(iframe);
    return iframe;
},

then in submit method

            var iframe = this._createIframe();

            // some synchronous operations

            addEvent(iframe, 'load', function (e) { // ...

Since this iframe has an src attribute, Chrome will start its loading, and since its src is a fake url, this operation actually is resolved synchronously, meaning that the load event is already set to fire at the next event-loop iteration.

const frame = document.createElement('iframe');
frame.src = 'javascript:return false';
document.body.append(frame);
frame.addEventListener('load', (evt) => console.log('loaded', frame.src) );

setTimeout( () => frame.src = "about:blank", 0 );

// Results in Chrome:
// loaded javascript:return false
// loaded about:blank

// Results in Firefox:
// loaded about:blank

So the one load event this library is receiving is that initial load event, of an empty document, and not the one of the real request.

To fix that, all you need is to remove this src="javascript:false;" from the library code: https://jsfiddle.net/9phxmqjw/

like image 195
Kaiido Avatar answered Oct 08 '22 22:10

Kaiido


I just set srcdoc attribute to iframe equals url in AjaxUpload component.

iframe.setAttribute('srcdoc', this._settings.action);

It's solved my problem.

Function into file AjaxUpload.js:

        _createIframe: function(){
            var id = getUID();            

            var iframe = toElement('<iframe src="javascript:false;" name="' + id + '" />');        
            iframe.setAttribute('id', id);
            iframe.setAttribute('srcdoc', this._settings.action);

            iframe.style.display = 'none';
            document.body.appendChild(iframe);

            return iframe;
        }
like image 20
Bakhyt Bekbolatuly Avatar answered Oct 08 '22 22:10

Bakhyt Bekbolatuly