Skip to content
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

Promise with @grant doesn't work on Safari #375

Closed
ccloli opened this issue Apr 1, 2017 · 7 comments
Closed

Promise with @grant doesn't work on Safari #375

ccloli opened this issue Apr 1, 2017 · 7 comments

Comments

@ccloli
Copy link

ccloli commented Apr 1, 2017

// ==UserScript==
// @name         Promise test
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      *
// @grant        GM_xmlhttpRequest

// ==/UserScript==

(function() {
    'use strict';
    
    Promise.resolve('Success').then(function(value) {
        console.log(value); // "Success"
    }, function(value) {
        console.log('??????');
    });
})();

In Chrome with Tampermonkey Beta v4.3.5421 it works fine, Success will be shown in console. And if the @grant is none, Safari will also show it. But when use specific @grant like GM_xmlhttpRequest, it will throw TypeError in Safari.

ni pbwk ztyeaohqid1v0j4

System: macOS Sierra (10.12.4)
Browser: Safari 10.1 (12603.1.30.0.34)
Extension: Tampermonkey v4.3.5421

@ccloli
Copy link
Author

ccloli commented Apr 20, 2017

Now temporary fixed with

if (!Promise || !Promise.resolve) {
	var Promise = unsafeWindow.Promise;
}

Anyway Promise is in standard ECMAScript, it shouldn't be blocked in sandbox, and it works fine in other browsers.

@derjanb
Copy link
Member

derjanb commented Apr 21, 2017

Sorry for the delay. Should be fixed now: http://tampermonkey.net/changelog.php?version=4.3.5437&ext=G3XV

@derjanb derjanb closed this as completed Apr 21, 2017
@pankajnarola1995
Copy link

pankajnarola1995 commented Feb 26, 2019

Hii, I'm still having the problem with Safari Browser.

i have the below code

// @grant        GM_xmlhttpRequest

GM_xmlhttpRequest({
            method: 'GET',
            url: url,
            responseType: 'json',
            onload: function (responseCurrentUser) {})

This works very fine in crome and firefox box in safari it gives this error...

response: Object

error: "Unauthorized"

error_description: ""

Object Prototype

responseHeaders: "access-control-expose-headers: Location
↵cache-control: no-cache, no-store, no-transform, must-revalidate
↵content-encoding: UTF-8…"

responseText: 

responseType: "json"

responseXML: 

status: 401

statusText: ""

The same code is working well for chrome and firefox.

I don't understand why? I tried to google it but not found answer.. so could you please tell me where I'm wrong? or what I'm missing?

@pankajnarola1995
Copy link

Sorry for the delay. Should be fixed now: http://tampermonkey.net/changelog.php?version=4.3.5437&ext=G3XV

I also had a look here, but no found the reason

@ccloli
Copy link
Author

ccloli commented Feb 26, 2019

@pankajnarola1995 The issue is about Promise is not working on Safari, not GM_xmlhttpRequest, maybe you should open a new issue.

BTW, the HTTP request returns 401 Unauthorized status, meaning that you're not login to the server or the server got an invalid session and reject your request, maybe you should check is there something wrong with your script or website.

@pankajnarola1995
Copy link

Hii, @ccloli thank you so much for reply. Yah I have noticed that and I have checked the login 10 times... and still, it's the same result..
The same happens into chrome and firefox browser when I did the log out, it threw the above error, but if I do the same in safari it's not working.. 😢

@ccloli
Copy link
Author

ccloli commented Feb 26, 2019

I'm not sure, maybe you should open a new issue and give a minimal script or steps that can reproduce your bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants