Commands

Add the Content Protection extension before using this command.

setContentProtectionPolicy

Validates and replaces the active policy.

editor.commands.setContentProtectionPolicy({ policy })

Parameters

  • policy (ContentProtectionPolicy): The complete replacement policy.

Returns (boolean)

  • true: The policy is valid, including when it is unchanged.
  • false: The policy is invalid or the transaction also changes document content.

A direct editor.commands.setContentProtectionPolicy({ policy }) call is synchronous: when it returns, the accepted policy and policyRevision are installed. With editor.chain(), installation happens when .run() dispatches the transaction. The contentProtectionPolicyUpdate notification is queued as a microtask after installation; it does not run before the command returns.

Behavior

  • A changed policy increments policyRevision and emits contentProtectionPolicyUpdate.
  • An identical policy has no effect and emits no event.
  • Invalid input keeps the previous policy and emits contentProtectionPolicyError.
  • The extension copies the policy. Mutating the supplied object has no effect.
  • Policy changes do not change document content or enter undo history.
  • Selection-only chaining is allowed. Replace the policy separately from content edits.
  • editor.can().setContentProtectionPolicy({ policy }) validates without changing state or emitting events.