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:
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:
Preferred: Open the framed document in its own tab and use the Page Editor
Use the Page Editor on the top-level tab, and manually write element selectors
Find the URL of the iframe
Use the Chrome Dev Tools element selector
Select an element within the frame
Find the iframe ancestor element. It will have tag <iframe> and show a #document sub node:
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
Find the URL of the iframe (see above)
Open a new tab and navigate to the document URL
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.
Find the URL of the iframe (see above)
Add the mod in the Page Editor
Modify the “Sites” to match the source of the framed document
Build the mod as normal, but manually write elements selectors. (Because the Page Editor cannot select elements in iframes)
Save the Mod
Right-click on the frame and select “Reload Frame” from the Chrome context menu:
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”
Configuring a brick to run in the top-level frame
Transferring Data from an Inline Frame to the Top-Level Frame
Approach 1: Assigning a Mod Variable in the Top-Level Frame
To make data from an inline frame available to the Top-Level Frame, use the Assign Mod Variable brick in conjunction with the Target Tab/Frame option.
When the brick runs, it will set the mod variable of the Top-Level Frame.
Sending data from an inner frame to the top-level frame
Approach 2: Running a brick in All Frames
To run a brick in all frames on the page, set the Advanced Options > Target Tab/Frame to “All Frames”. The brick will return an array of values (a value per frame)
Configuring a brick to run in All Frames
Transferring Data from the Top-Level Frame to an Inline Frame
Approach 1: Push data from the Top-Level Frame to All Frames
To push data from a Top-Level Frame to frames on the page. Use the Assign Mod Variable brick and set the Advanced Options > Target Tab/Frame to “All Frames”.
Assigning a Mod Variable in All Frames
Approach 2: Read/Poll data from the Top-Level Frame
To retrieve information from the Top-Level Frame, set Advanced Options > Target Tab/Frame for the brick to "Top-Level Frame":
Configuring a brick to run in the Top-Level Frame
To read the Mod Variables from the Top-Level Frame, use the Get shared page state brick:
Reading Mod Variables from the Top-Level Frame
Determining When to Read/Poll Information from the Top-Level Frame
An Inline Frame may load 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 Top-Level Frame 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
Example configuration of the “Post message to a frame” brick
Working with Salesforce CK Editor
Extracting Text from the CK Editor
To extract text from the CK Editor, you'll need to use the Run Bricks brick (target in All Frames), with the Traverse Elements brick targeting body[contenteditable="true"]. Then add the HTML Reader brick to reference the output element. Here's an example:
Inserting Text into the CK Editor
To insert text, you can use the same Run Bricks brick in All Frames, and inside use the Insert HTML Element targeting the body[contenteditable="true"] selector to prepend the element.