"0" shows up in the JavaScript autocomplete list

Hello there. So, I was experimenting with autocompletion in a JavaScript CodeMirror component, and I used this extension in my code:

javascriptLanguage.data.of({autocomplete: scopeCompletionSource(globalThis)})

Now, it shows 0 in the completion list:

Screenshot 2022-10-17 155656

I would rather not have a random “0” in the list. Is there any way to remove it?

Could it be that some script is defining window[0] to hold some value? scopeCompletionSource just shows the properties from the object it is given, and I don’t think it would be appropriate to put some random filtering heuristic in there. I’m not seeing this on the codemirror.net demo. Are you?

It turns out that an iframe in my page is defining window[0] as the frame window. I wasn’t able to fix this, since I need iframes in my website for it to work properly.

One solution would be to create a fresh iframe and use its contentWindow (which should not have custom variables in it) as your completion object.

Well, that seemed to work quite nicely. Thank you!

Also, sorry I couldn’t reply earlier. I wasn’t able to check the discussion board the past few days.

In fact, I was actually thinking about doing that originally, but I didn’t think CodeMirror 6 would detect any new variables defined in the editor’s “value”. It turns out it does, which was quite surprising to me.