Window (Javascript)
An overview of the global window.lantern object for interacting with Lantern on the storefront.
The window.lantern
object is a global JavaScript object available on your Shopify theme when the Lantern app is installed and active. It serves as the primary interface for interacting with Lantern from the storefront.
Accessing the window.lantern
Object
You can access the window.lantern
object directly from any script running on your storefront.
if (window.lantern) {
console.log('Lantern is available!', window.lantern);
}
Initialization
The window.lantern
object is initialized asynchronously. You should ensure the object and its
properties are available before attempting to use them. You can listen for the lantern:loaded
event on the window
object to know when it's safe to interact with the API.
window.addEventListener('lantern:loaded', () => {
console.log('Lantern is now fully loaded and ready to use.');
// You can now safely use window.lantern properties
const customer = window.lantern.customer;
});