[SOLVED] Not able to access global variable in chrome console when i publish my project

Hello, I am working on a project where I am dealing with APIs and storing data in a global variable for some purpose. Here is how I am writing it(check the screenshot)


I am updating the loggedStatus, userId, and emailId when a user logs in. And when I try to launch from the playcanvas editor I can access this data in the browser console by writing “digitalData”.


But when i publish my project and try to do the same and access this variable it shows this error(check screenshot)


Can anyone tell me why this is happening and if we can’t do it what is the other way to do this? Any help would be great. Thanks have a good day :smiley:

Maybe you are reading it from a wrong window? For example, an iframe has its own window, then its parent has own one, etc.

@LeXXik sorry but i was not able to understand your reply when I was in the editor and launched to test this thing it worked i just typed digitalData in the browser console it did show the data. But when I did the same thing in the published project it said undefined(i typed the same name digitalData in the console). if I am reading from the wrong window then it shouldn’t be working in the editor version right? :thinking:

Perhaps, perhaps not. I don’t know how you publish it or try to access the property. Maybe when you publish and concatenate the scripts, the property gets moved and accessed in the wrong order? Try creating a separate script with no contents in it, except that global object assignement on window and set its loading type to be loaded after engine in the Editor inspector panel.


@LeXXik I did what you asked putting the global variable in a script and changing it to AFTER ENGINE
It still says the same but this time it didn’t work in the editor either. It works only when I change the option to ASSET.

Published builds on PlayCanvas has the game in an iframe

So your console is currently in the context of the ‘framing’ page and not the game itself

You can either change devtools console to be in the context of the game iframe

Or get the iframeless version of the build via Exported Project as iFrame - #2 by yaustar


Thank you so much @yaustar. I get it now its showing for me now :smiley: