Class

SafariExtensionSettings

The SafariExtensionsSettings class provides a place for your extension to store settings that should persist between sessions.

Overview

You can access settings using the provided methods or using JavaScript’s built-in syntax, as follows:

// Get a value.
safari.extension.settings.someProperty
safari.extension.settings["someProperty"]
safari.extension.settings.getItem("someProperty")
 
// Set a value.
safari.extension.settings.someProperty = 42;
safari.extension.settings["someProperty"] = 42;
safari.extension.settings.setItem("someProperty", 42);
 
// Delete a value.
delete safari.extension.someProperty;
delete safari.extension["someProperty"];
safari.extension.removeItem("someProperty");

Note that there is a minor difference for properties that don’t exist: JavaScript’s build-in syntax returns undefined, but the getItem method returns null.

Topics

Reading and Writing Settings

getItem

Returns the current value of a key.

setItem

Sets the value of a key.

Removing Settings

removeItem

Removes a key.

clear

Removes all key-value pairs.

Relationships

Inherits From