Contents

init(source:injectionTime:forMainFrameOnly:in:)

Creates a user script object that is scoped to a particular content world.

Declaration

init(source: String, injectionTime: WKUserScriptInjectionTime, forMainFrameOnly: Bool, in contentWorld: WKContentWorld)

Parameters

  • source:

    The script’s source code.

  • injectionTime:

    The time at which to inject the script into the webpage. For a list of possible values, see Wkuserscriptinjectiontime.

  • forMainFrameOnly:

    A Boolean value that indicates whether to inject the script into the main frame. Specify True to inject the script only into the main frame, or False to inject it into all frames.

  • contentWorld:

    The namespace in which to evaluate the script. This parameter doesn’t apply to changes your script makes to the underlying web content, such as the document’s DOM structure. Those changes remain visible to all scripts, regardless of which content world you specify. For more information about content worlds, see Wkcontentworld.

Return Value

An initialized user script, or nil if initialization failed.

See Also

Creating a User Script Object