Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:58:26+00:00 2026-05-24T03:58:26+00:00

When I tried to play around with Web Workers feature in HTML5, my firefox

  • 0

When I tried to play around with Web Workers feature in HTML5, my firefox works happily but chrome complains that:

Uncaught TypeError: Cannot call method ‘postMessage’ of undefined
xstartWorkerworker.html:7 (anonymous function)worker.html:1
onclickworker.html:2

worker.html

<button onclick="xstartWorker()">Start worker</button>
<output id="result"></output>
<script>
function xstartWorker()
{
  worker.postMessage({'cmd': 'startWorker', 'msg': 'Start now!'});
}

var worker = new Worker('worker.js');

worker.addEventListener('message', function(e)
  {
      document.getElementById('result').textContent = e.data;
  }
  , false);
</script>

worker.js

self.addEventListener('message', function(e)
{
  var data = e.data;
  switch (data.cmd)
  {
    case 'startWorker':
      self.postMessage('worker thread start now:' + data.msg);
      break;
    default:
      self.postMessage('default');
  }
}
, false);

What I can do to make it works in chrome?

BTW, when I tried out the sample at http://playground.html5rocks.com/#inline_workers
and this time chrome works, but firefox complains that

Error: worker is undefined Source File:
http://playground.html5rocks.com/ Line: 39

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:58:27+00:00Added an answer on May 24, 2026 at 3:58 am

    I’m guessing you’re trying to run this on your local machine, not on a webserver. Workers are restricted by the Same Origin Policy, but as the linked Wikipedia page notes,

    The behavior of same-origin checks and related mechanisms is not
    well-defined in a number of corner cases, such as for protocols that
    do not have a clearly defined host name or port associated with their
    URLs (file:, data:, etc.).

    Loading a local file, even with a relative URL, is the same as loading a file with the file: protocol. So my guess is that the problem is that you’re trying to load worker.js as a local file – Chrome doesn’t like this (for some good security reasons), though you can force the issue by starting Chrome like this: chrome.exe --allow-file-access-from-files

    Alternatively, try serving your script on a local or remote webserver and see if that fixes the problem. (If you have Python installed, you can go to the directory in question and run python -m SimpleHTTPServer 8000, then go to http://localhost:8000/ in your browser).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

tried to research on that but sometimes I seem to lack some googling skills...
I recently started to play around with Amazon SES. When I intentionally tried to
I wanted to play around with Linux and do some testing. I've tried installing
I just started to play around with MongoDB (C#) and tried to port a
I need to play frame based animations. I tried the UIImageView with animationImages but
I've got a little web app that I made to play with Android's WebView
I'm brand new to node.js, but I wanted to play around with some basic
I want to create a chat room using HTML5 web sockets, but am pretty
My food menu works perfectly in Firefox and IE, but not at all on
I have a .wav music file. When I tried to play using SoundEffect.Play(); mus1.Play();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.