Skip to content

Download a file via HTML5 Blob API: Failed to get remote object proxy #91

@loretoparisi

Description

@loretoparisi

I'm using the recent (actually not so recent) HTML5 Blob API to download a file from a JavaScript client like

/**
     * Save a text as file using HTML <a> temporary element and Blob
    */
    var saveAsFile = function(fileName,fileContents) {
        if(typeof(Blob)!='undefined') { // using Blob
            var textFileAsBlob = new Blob([fileContents], { type: 'text/plain' });
            var downloadLink = document.createElement("a");
            downloadLink.download = fileName;
            if (window.webkitURL != null) {
                downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
            }
            else {
                downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
                downloadLink.onclick = document.body.removeChild(event.target);
                downloadLink.style.display = "none";
                document.body.appendChild(downloadLink);
            }
            downloadLink.click();
        } else {
            var pp = document.createElement('a');
            pp.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(fileContents));
            pp.setAttribute('download', fileName);
            pp.onclick = document.body.removeChild(event.target);
            pp.click();
        }
    }//saveAsFile

When the Blob is not supported it uses the standard DOM way.
When I run my application within MacGap2 running this code called let's say like:

saveAsFile('my_report.json',jsonString);

will lead to this error:

2018-04-23 19:35:08.270857+0200 sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service named com.apple.rtcreportingd}

I'm not sure if this is connected to the secure transport due to the NSAppTransportSecurity, but in my case I'm creating a downloadable content on the fly, which url is on localhost.

I have also tried to intercept the link click through the PolicyDelegate, but for some reason I do not get any log here:

- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener
{
    if (WebNavigationTypeLinkClicked == [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue])
    {
        NSLog(@"CLICKED %@", [request URL]);
    }
    [[NSWorkspace sharedWorkspace] openURL:[request URL]];
    [listener ignore];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions