Skip to content

Commit

Permalink
[search] Add a warning when instantiating a worker from file://.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Jul 27, 2023
1 parent 5bf4b78 commit 77ffa76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cubing/search/instantiator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export async function mapToAllWorkers(

async function instantiateWorkerImplementation(): Promise<InsideOutsideAPI> {
if (globalThis.location?.protocol === "file:") {
console.error(
"This current web page is loaded from the local filesystem (the URL starts with `file:`). In all modern browser, `cubing.js` is unable to generate scrambles in this situation. See: https://js.cubing.net/cubing/scramble/#random-scramble",
console.warn(
"This current web page is loaded from the local filesystem (a URL that starts with `file://`). In this situation, `cubing.js` may be unable to generate scrambles in some browsers. See: https://js.cubing.net/cubing/scramble/#file-server-required",
);
}

Expand Down
29 changes: 26 additions & 3 deletions src/docs/js.cubing.net/cubing/scramble/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,33 @@ <h1><a href="#random-scramble">Random Scramble</a></h1>
href="https://www.worldcubeassociation.org/regulations/scrambles/">the official scramble program</a>.</li>
</li>
</ul>
Also:
</p>
</section>

<section id="file-server">
<h1><a href="#file-server-required">Using a file server</a></h1>
<p>
If you want to generate scrambles using <code>cubing.js</code>, please
ensure the page is accessed from a server using a URL that starts with one of the following:
<ul>
<li>☑️ <code>http://</code></li>
<li>☑️ <code>https://</code></li>
</ul>
Scramble generation will not work in Google
Chrome if your browser is showing a file from your file system using a URL
that starts with:
<ul>
<li>This code requires the page to be accessed from a server (either from the internet or
<code>localhost</code>). It will not work for <code>file://</code> URLs, due to browser security restrictions.
<li>🙅 <code>file://</code></li>
</ul>
</p>
<p>
If you need to use a file server for local development, you may find one of the following commands useful:
<ul>
<li>
<code>python3 -m <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/set_up_a_local_testing_server#using_python">http.server</a></code>
</li>
<li><code>npx <a href="https://www.npmjs.com/package/serve">serve</a></code></li>
<li><code><a href="https://caddyserver.com/">caddy</a> file-server --listen :8000 --browse</code></li>
</ul>
</p>
</section>
Expand Down

0 comments on commit 77ffa76

Please sign in to comment.