Replit webview loads page twice, causes errors

How do I avoid replit loading a page in the webview twice. It’s annoying visually, but worse that it causes my JS to break. In the example below, opening the second page includes a simple script to set a const to the current time and render it within a div. Because of the issue, the page is loaded twice, and error occurs because an identifier is already declared. This issue does not occur if you open the site in a new tab.


https://replit.com/@HarrisonRose/Flask-Issue-Test


I’ve reduced it down to its basics so you can see the issue in the link

1 Like

Hey there! It seems like you’re having some trouble with Replit loading pages twice, which is causing some JavaScript issues. Don’t worry though, we can fix this together!

Firstly, could you try opening your project in a new tab? This could help to remove any errors caused by the issue.

Next, it’s worth checking your code for any duplicated calls. This can often be the root of the problem and is easily fixed.

If that doesn’t solve things, why not try clearing your browser cache and cookies? This can help to reset the page and hopefully resolve any lingering issues.

And finally, if all else fails, a good old refresh can often do the trick.

So, sometimes I port games I exported from godot(exported in HTML5), the game has an error in the editor webview.

I sometimes export my games to Replit, to test them, or to play them on my Xbox(yes)

The editor, and only the editor’s webview has this error happen.

If you need to look at my repl, go here.

Related to PHP Post Request Refreshes (replit.com). Workaround: enter into the address bar, to disable the devtools wrapper:

javascript:(()=>{let i=document.querySelector("iframe"),{src}=i;i.src=src.slice(6,-31)})()

You could use a user-script browser extension to have this run on your repl’s URL.

1 Like

How do I insert it into the script? (Im adding this to the exported script, and your may have to check my code out to find where to put it, because there’s multiple JavaScript files)

Enter the code into the address bar (the text box on the top of your browser window) while you’re in the Workspace. You could drag that code into your favourites bar and click the favourite created whenever you want to disable the devtools wrapper, or make the script run on your repl’s URL using something like tampermonkey.

I mean having that code be in a script file so people who want to fork my repl for whatever reason will have it run so the editor webview will work for them, even if they don’t paste the code into the url.

unfortunately impossible, because you can’t modify the repl from the webview as the origins are different. Most you can do is this (using Shell because loading the large file in the editor might take ages):

sed -i '1iif (top != parent) {\
  location = `data:text/html,Not supported in webview. Open in new tab, or drag this to your favourites bar, if not done already, then click the new favourite each time you want to run: <a href='"'"'javascript:(()=>{let i=document.querySelector("iframe");i.src=src.slice(6,-31)})()'"'"'>Devtools disabler`\
}'  'Geometry Dash: Corruption(Fanmade edition).js'

For any others wanting to do this: be sure to replace the '…js' with the filename of the first script file that is referenced by your HTML file.
Although, in this case (a ported game), I’m not sure why you’d want to use the webview over new tab really.