Window/browser Session storage read in use API




I am trying to put some logic based on the value of a variable in session storage, based on session storage value i need to read some OSGI configuration. I am putting the read logic in use-API of HTL like below.

Component HTML file :-

<sly data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}">

            <clientlib data-sly-call="${clientLib.js @ categories='digitalexp-ss-l9-navigation'}" data-sly-unwrap/>


            <div data-sly-use.roleLogic="clientlibs/navigation/js/role.js">

                Logged In Role :-  ${roleLogic.userRole}


JS file :-

"use strict";

use(function () {

var loggedInUserRole = window.sessionStorage.getItem("userRole");

    return {




But i am getting below exception  even i dont include as clientLib:- Cannot get DefaultSlingScript: org.mozilla.javascript.EcmaError: ReferenceError: "window" is not defined.

could anyone give some pointer how to read session storage value which is being populated by some external REST services.

Note :- i am using @AEM

Accepted Solutions (1)

Accepted Solutions (1)




The window objects are just provided by web-browsers and are not part of the ECMAScript standard which Rhino implements. They are there to allow a script to access the current browser window and the HTML document. The document object is actually an implementation of the W3C DOM.

The local storage, as its name indicates, stores information locally, which means in the browser, at client-side. The JS server API executes at server-side. There is no way to access the local storage at server-side.

If you need to put some logic based on role, then retrieve this ID from the local storage in JavaSCript, and send a request containing this role to the server.

Answers (0)