javascriptfirefox

The cause for TypeError: access to strict mode caller function censoered


I'm working on a web application that uses the JMol Javascript extension with Angular. This is challenging. It's been working quite well, but today it stopped working on Firefox. When I try something JMol complains with the error

TypeError: access to strict mode caller function censored

This is happening in 3rd party code, only on Firefox (which has updated itself yesterday). It works well on Chrome.

I found some people complaining about a similar error over the years (without using JMol). They all received interesting answers - downgrading jQuery to 1.1, wrapping some function call in setTimeout and other such answers.

I could not find an explanation for the cause of this error. What is a strict mode caller, which access is censored, and why? I would also love to see a minimal piece of code that generates this error on Firefox - so I can understand what I'm trying to fix.


Solution

  • Note: Here in 2025, Firefox's SpiderMonkey doesn't seem to throw this error anymore, it just returns null the way Chromium's V8 does.


    What's happening is that code that tries to use the caller property of a function is being called by strict-mode code. Example:

    function attemptToUseCaller() {
        console.log(attemptToUseCaller.caller.name);
    }
    function loose() {
        attemptToUseCaller();
    }
    
    function strict() {
        "use strict";
        attemptToUseCaller();
    }
    loose();
    strict();

    If you run that in an up-to-date version of Firefox, you'll see this in the console:

    loose
    TypeError: access to strict mode caller function is censored
    

    As you can see, accessing attemptToUseCaller.caller worked when the calling function was in loose mode, but failed when the calling function was in strict mode. Accessing the caller property is disallowed in strict mode, and even disallowed when used in "loose" code, if the caller function is itself strict. Firefox raises a specific error, whereas with Chrome's V8 JavaScript engine, it just returns the value null for .caller in strict mode.

    Using caller is an anti-pattern. You'll need to fork whatever 3rd-party code is using it and correct it.