Editing Pages with iFrames

Inline Frames

An iframe (inline frame) is used to embed a document inside the current document. The embedded document can be from the same site, or a different site.

Framed documents are separate/distinct from the top-level tab. A separate β€œinstance” of PixieBrix runs in each iframe.

The Page Editor works on the top-level frame of the tab. It cannot directly select/modify elements in the document embedded within an iframe.

In selection/placement mode, when part of the page is an iframe, PixieBrix will highlight the whole iframe on hover because to the Page Editor, the iframe is a single element:

Editing a Framed Page

IFrames are distinct documents. To edit a document in an iframe with PixieBrix, you’ll edit the document and not the containing tab.

To extend a framed document with PixieBrix, you have two options:

  1. Preferred: Open the framed document in its own tab and use the Page Editor

  2. Use the Page Editor on the top-level tab, and manually write element selectors

Find the URL of the iframe

  1. Use the Chrome Dev Tools element selector

  2. Select an element within the frame

  3. Find the iframe ancestor element. It will have tag <iframe> and show a #document sub node:

  4. Right click the src attribute value and click β€œCopy link address”. This will copy a link address to the clipboard (including the origin if the src attribute does not already include it)

Opening the Framed Document in its Own Tab

Not all framed pages can be opened in their own tab. Some documents are configured to re-direct if they detect they’re not running inside a frame

  1. Find the URL of the iframe (see above)

  2. Open a new tab and navigate to the document URL

  3. Open the Page Editor and edit the page as usual

Editing from the Top-Level Tab

The Page Editor dynamically updates mods on the top-level tab. To run an updated mod in the iframed documents, you must Save the mod.

  1. Find the URL of the iframe (see above)

  2. Add the mod in the Page Editor

  3. Modify the β€œSites” to match the source of the framed document

  4. Build the mod as normal, but manually write elements selectors. (Because the Page Editor cannot select elements in iframes)

  5. Save the Mod

  6. Right-click on the frame and select β€œReload Frame” from the Chrome context menu:

  7. Your Mod will run inside the framed document

Cross-frame Communication

Running a Brick in the Top-Level Frame on a Tab

To run a brick in the top-level frame on the page, set the Advanced Options > Target Tab/Frame to β€œTop-level Frame (top)”

Transferring Data from an Inline Frame to the Top-Level Frame

To make data from an inline frame available to the Top-Level Frame, use the β€œSet Shared Page State” brick in conjunction with the Target Tab/Frame Setting

When the brick runs, it will set the value in the state of the Top-Level Frame.

Transferring Data from the Top-Level Frame to an Inline Frame

PixieBrix does not currently support pushing data directly from a Top-Level Frame to an Inline Frame.

Instead, to transfer data from the Top-Level Frame to an Inline Frame, the Inline Frame must request/poll for the information from the Top-Level Frame.

To retrieve information from the Top-Level Frame, use Advanced Options > Target Tab/Frame for the brick.

For example, to extract the header from the Top-Level Frame using the Extract from Page brick:

The Inline Frame can also read from the Page State of the Top-Level Frame using the β€œGet Shared Page State Brick”.

Determining When to Retrieve/Poll Information from the Top-Level Frame

An Inline Frame may be initialized prior to the Top-Level Frame being ready. Therefore, you must take extra steps to ensure that the data is available reliably.

Some common approaches are:

  • If the data is loaded on page load: Use the "Wait for a DOM element” brick with Target Tab/Frame: Top-level Frame to wait for the information to be available

  • If the data may change: Use an Interval Trigger as the Starter Brick to poll for data

  • Use Wait/Sleep to provide an opportunity for the native page to load

Sending Messages to Frames to Trigger Native Javascript Handlers with the β€œPost Message to a Frame” brick

This use case is advanced/special. You generally will not use the β€œPost Message to a Frame” brick unless you are instructed to by the host application’s documentation

Some Javascript applications listen for events from other frames to support events and data transfer. These applications use the Javascript Window postMessage API

To send a message to a frame on the page, use the β€œPost Message to a Frame” brick. The brick has the following options:

  • selector: the iframe to message

  • message: the message payload. The shape will depend on what the receiver/listener expects to receive

  • targetOrigin: the origin (schema, hostname, port) of the intended recipient, or * not to validate the target frame’s origin. Used to prevent sending sensitive information to the wrong location

Last updated