'The object could not be cloned' and 'view-source:user-script:' schema

22 views
Skip to first unread message

Bela Lubkin

unread,
Apr 3, 2020, 12:26:59 AM4/3/20
to greasemon...@googlegroups.com
Hi,

I'm fooling around with porting a large script to GM4.  At the moment I'm getting several runtime errors like so:

<< set value failed: DOMException: "The object could not be cloned." Social Fixer for Facebook:11273:9 >>

Hovering ':11273:9' shows 'View source in Debugger', with a 'user-script:' schema link.  Clicking through leads to the address 'view-source:user-script:http%3A//userscripts.org/users/864169999/Social%20Fixer%20for%20Facebook', and the page contents:

<<
The address wasn’t understood

Firefox doesn’t know how to open this address, because one of the following protocols (view-source, user-script) isn’t associated with any program or is not allowed in this context.

    You might need to install other software to open this address.
>>

This is a problem because the reported line numbers seem to be non-linearly related with actual script line numbers.  For instance, the first few lines of the script are reported as line numbers in the 500 range.

For other errors I was able to use the crude workaround of: add a blank line a bit before where I think the error is, then see if the reported line number goes up by 1.  If so, the error line is after the blank line; else before.  Binary search.  In doing this, the delta offset between the 'found' line number and the reported one is not a constant; I can't just subtract 517 (or some such value) from the reported line number.

Unfortunately, for the '11273:9' error, the binary search indicates the problem line is AFTER the last line of the script!

Clearly GM is prepending and appending lines to the input userscript, and I'm hitting problems on those lines. The script-as-tested this time is 10739 lines long; the known offset hovers around 500 lines; so whatever's going wrong is only a few (or few dozen) lines into the appended stuff.

So the various problems I'm hitting are:

- << DOMException: "The object could not be cloned." >> for unknown reasons
- not able to view source, 'view-source:user-script:' schema not understood
- error message line number references are offset (non-linearly)
- the 'DOMException' failing line is after the end of the actual userscript
- (an FF bug or annoyance: 'one of the following protocols (view-source, user-script)' is annoyingly non-specific.  In this case I know that view-source: works elsewhere, so it must be tripping on user-script:; it should just say so.)

Stuff in use: Linuxmint 17.3 (olllld); Firefox 66.0.3 (held back by back-rev OS); Greasemonkey 4.9.

========================

OHO, HOLD EVERYTHING.  I became embarrassed at only trying it in FF-old, remembered I had FF-nightly installed, and -- things are different there.

Retested with 'Firefox 76.0a1 (2020-03-31) (64-bit)' -- a few days out of date.  Stepping through the summary list of problems above,

- << DOMException: "The object could not be cloned." >> -- still happens
- embedded 'view-source' URL works, brings up annotated wrapped userscript in dev tools Debugger pane
- line numbers are offset less (? GM injects fewer old-FF workarounds at the top of the script?)
- failing line is off the end of the userscript
- FF error msg bug/annoyance not exercised

Error is now happening at:

10769 GM.setValue = function GM_setValue(key, value) {
10770   return new Promise((resolve, reject) => {
10771     chrome.runtime.sendMessage({
10772       'key': key,
10773       'name': 'ApiSetValue',
10774       'uuid': _uuid,
10775       'value': value,
10776     }, result => {
10777       if (result !== undefined) {
10778         resolve(result);
10779       } else {
10780 ==>     console.warn('set value failed:', chrome.runtime.lastError);
10781         reject();
10782       }
10783     });
10784   });
10785 };

and appears to be due to trying to stash a Promise into setValue() (due to my buggy use of getValue()).

SO: most of my issue(s) are resolved, but seem to point up several GM issues:

- inaccurate line numbers in error msgs
- source viewing not working in older FF
- unhelpful error reporting:

'set value' is super generic, could come from almost any sort of code anywhere.  Change to 'GM.setValue failed' and it would have been more obvious.  Even better:

  console.warn('GM.setValue failed:',chrome.runtime.lastError);
 console.warn('key',key);
 console.warn('value',value);

-- reporting values separately in case they would cause console.warn() to fail.

Thanks,

>Bela<

[ Leaving my journey of discovery for others, because, had I found this in my Google search on << "DOMException the object could not be cloned" >>, I'd have saved a bunch of time... ]
Reply all
Reply to author
Forward
0 new messages