userscripts icon indicating copy to clipboard operation
userscripts copied to clipboard

DuckDuckGPT safari

Open Delamcode opened this issue 2 years ago ā€¢ 78 comments

I know there is not official support, but using the userscripts extension I get this error: GM_getValue is not a function. (In 'GM_getValue("accessToken")', 'GM_getValue' is undefined). Do you have an idea of what is causing this? Here is the extension readme: https://github.com/quoid/userscripts

Delamcode avatar Feb 19 '23 13:02 Delamcode

Hey, I don't have a Mac so can't test support but can you try it using Tampermonkey @ https://www.tampermonkey.net/index.php?browser=safari&locale=en

adamlui avatar Feb 19 '23 13:02 adamlui

No, unfortunately I canā€™t. I was just wondering if it is something that would be easy to fixā€¦

Delamcode avatar Feb 19 '23 13:02 Delamcode

How come? If you could it would probably work, GM_getValue is a function supported by userscript managers like Tampermonkey & Violentmonkey, the readme you linked is for a userscript editor only

adamlui avatar Feb 19 '23 14:02 adamlui

Because only userscripts supports ipad. It is not only an editor. Here is the popup in safari: https://github.com/quoid/userscripts#popup

Delamcode avatar Feb 19 '23 14:02 Delamcode

Ohh, well I asked da bot and it said:

image

Do you know how to edit the code? Can you remove line 17:

// @grant GM_getValue

Remove line 29:

var GM_getValue = (() => window.GM_getValue)()

And finally, replace line 168 with:

var accessToken = await localStorage.getItem("accessToken")

...and let me know if it works?

adamlui avatar Feb 19 '23 14:02 adamlui

Weirdā€¦ the readme says it is supported but Iā€™ll try and report back

Delamcode avatar Feb 19 '23 14:02 Delamcode

Ok then

adamlui avatar Feb 19 '23 14:02 adamlui

Actually you could try asking the extension author why the function wasn't supported on your iPad, and maybe provide them screenshots + link to my code

adamlui avatar Feb 19 '23 14:02 adamlui

I now get this error: undefined is not a function (near '...GM_xmlhttpRequest...') asyncFunctionResume@[native code] @[native code] promiseReactionJobWithoutPromise@[native code] appendChild@[native code] injectJS@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:274:34 processJS@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:222:21 @safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:402:18

Delamcode avatar Feb 19 '23 14:02 Delamcode

Actually you could try asking the extension author why the function wasn't supported on your iPad, and maybe provide them screenshots + link to my code

Sure, I could try

Delamcode avatar Feb 19 '23 14:02 Delamcode

Is there any setup Iā€™m missing?

Delamcode avatar Feb 19 '23 14:02 Delamcode

I now get this error: undefined is not a function (near '...GM_xmlhttpRequest...') asyncFunctionResume@[native code] @[native code] promiseReactionJobWithoutPromise@[native code] appendChild@[native code] injectJS@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:274:34 processJS@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:222:21 @safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:402:18

Yeah it looks like none of the GM_ functions are supported by that extension & DuckDuckGPT uses these 5:

// @grant GM_deleteValue // @grant GM_getValue // @grant GM_setValue // @grant GM_info // @grant GM_xmlhttpRequest

adamlui avatar Feb 19 '23 14:02 adamlui

Interestingā€¦ I wonder why they donā€™t work as here it claims itā€™s supportedā€¦

Delamcode avatar Feb 19 '23 14:02 Delamcode

Could it be that userscripts uses GM.[Item] instead of GM_[Item]?

Delamcode avatar Feb 19 '23 14:02 Delamcode

Opened an issue on the extension ^^

Delamcode avatar Feb 19 '23 15:02 Delamcode

Maybe it has something to do with this?

Delamcode avatar Feb 19 '23 15:02 Delamcode

Maybe it has something to do with this?

I'ma look at it tonight after I sleep (I was up all night)

adamlui avatar Feb 19 '23 16:02 adamlui

According to the other issue I should change it to GM. but then I get this error (will edit if anything changes): ReferenceError {} column: 43 line: 87 message: "Can't find variable: GM_registerMenuCommand" sourceURL: "https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad" stack: "enableCommandMenu@https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad:87:43ā†µmain@https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad:54:26ā†µ@https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad:112:17ā†µ@https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad:179:3ā†µ@https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad:181:15ā†µglobal code@https://duckduckgo.com/?q=what+is+the+meaning+of+life&t=ipad:182:11ā†µappendChild@[native code]ā†µinjectJS@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:274:34ā†µprocessJS@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:222:21ā†µ@safari-web-extension://F0435466-F9A8-46C1-B498-8953D9410A63/content.js:402:18" __proto__: Object

Delamcode avatar Feb 19 '23 19:02 Delamcode

I am one of the maintainers of the previously mentioned user script manager. The reason an error is thrown is because synchronous GM_ apis are not supported by the manager (outside of GM_info and GM_xmlhttpRequest). Only certain async counter parts are supported - readme. The main difference in these api methods being sync vs async.

I recommend the newer API methods, but thats obviously up to the user script author. If you'd like to support the newer API methods you could do something like:

...
// @grant            GM_deleteValue
// @grant            GM_getValue
// @grant            GM_setValue
// @grant            GM_info
// @grant            GM_xmlhttpRequest
// @grant            GM.deleteValue
// @grant            GM.getValue
// @grant            GM.setValue
// @grant            GM.info
// @grant            GM.xmlHttpRequest
...
var GM_setValue = (() => window.GM_setValue ?? GM.setValue)()
var GM_deleteValue = (() => window.GM_deleteValue ?? GM.deleteValue)()
var GM_info = (() => window.GM_info ?? GM.info)()
var GM_xmlhttpRequest = (() => window.GM_xmlhttpRequest ?? GM.xmlHttpRequest)()
var GM_getValue = (() => window.GM_getValue ?? GM.getValue)()
...

quoid avatar Feb 19 '23 19:02 quoid

Using just these updates makes it ā€œworkā€ but asks to log in even though Iā€™m logged inā€¦

Delamcode avatar Feb 19 '23 19:02 Delamcode

@Delamcode did you revert the edits in https://github.com/adamlui/userscripts/issues/10#issuecomment-1436006798 before applying @quoid's tweak? If so, I asked da bot and apparently the "nullish coalescing operator (??), which is a relatively new feature introduced in ECMAScript 2020 [is not always supported]. Unfortunately, not all browsers support this feature yet, including some versions of Safari on iPad."

Can you try replacing them with the OR operator?

var GM_setValue = (() => window.GM_setValue || GM.setValue)() var GM_setValue = (() => window.GM_setValue || GM.setValue)() var GM_deleteValue = (() => window.GM_deleteValue || GM.deleteValue)() var GM_info = (() => window.GM_info || GM.info)() var GM_xmlhttpRequest = (() => window.GM_xmlhttpRequest || GM.xmlHttpRequest)() var GM_getValue = (() => window.GM_getValue || GM.getValue)()

Also what version of Safari are you using, is it 10+?

adamlui avatar Feb 21 '23 03:02 adamlui

I am using safari 15. Yes, I did revert. I will try this.

Delamcode avatar Feb 21 '23 06:02 Delamcode

Now both methods stopped workingā€¦ (Waiting for Response) with this error: JSON Parse error: Unrecognized token '<' onload@ @safari-web-extension://ED32EE2A-2F54-40AF-89E4-E1F764226C05/content.js:180:38 asyncFunctionResume@[native code] @safari-web-extension://ED32EE2A-2F54-40AF-89E4-E1F764226C05/content.js:156:59

Delamcode avatar Feb 21 '23 06:02 Delamcode

Actually I just found out ChatGPT's been down forever... image So can you go back to using the ??'s, I think it might work when they're back up

adamlui avatar Feb 21 '23 11:02 adamlui

The actual website is working fine for me, and I am logged in. Using ?? I still get the log in @ error, even though Iā€™m logged inā€¦

Delamcode avatar Feb 21 '23 12:02 Delamcode

Is it possible to console.log the id on my computer, and then hard code it on my ipad script?

Delamcode avatar Feb 21 '23 13:02 Delamcode

Is it possible to console.log the id on my computer, and then hard code it on my ipad script?

Probably, also you could try adding 'GM_deleteValue("accessToken")' after line 27, save, refresh search page, then remove the line, re-save, then refresh search page (just to clear it out)

adamlui avatar Feb 21 '23 13:02 adamlui

Where (and how) would you recommend doing the console.log?

Delamcode avatar Feb 21 '23 13:02 Delamcode

Can you try clearing the access token first see if that works? (I had to do this in incompatible browsers & it worked is why I didn't include them)

adamlui avatar Feb 21 '23 13:02 adamlui

No it didnā€™t work. After declaring the var right? Because line 27 isnā€™t the same for us

Delamcode avatar Feb 21 '23 13:02 Delamcode