labvanced logoLabVanced
  • Research
    • Publications
    • Researcher Interviews
    • Use Cases
      • Developmental Psychology
      • Linguistics
      • Clinical & Digital Health
      • Educational Psychology
      • Cognitive & Neuro
      • Social & Personality
      • Arts Research
      • Sports & Movement
      • Marketing & Consumer Behavior
      • Economics
      • HCI / UX
      • Commercial / Industry Use
    • Labvanced Blog
    • Services
  • Technology
    • Feature Overview
    • Code-Free Study Building
    • Eye Tracking
    • Mouse Tracking
    • Generative AI Integration
    • Multi User Studies
    • More ...
      • Reaction Time/Precise Timing
      • Text Transcription
      • Heart Rate Detection (rPPG)
      • Emotion Detection
      • Questionnaires/Surveys
      • Experimental Control
      • Data Privacy & Security
      • Desktop App
      • Mobile App
  • Learn
    • Guide
    • Videos
    • Walkthroughs
    • FAQ
    • Release Notes
    • Documents
    • Classroom
  • Experiments
    • Cognitive Tests
    • Sample Studies
    • Public Experiment Library
  • Pricing
    • Licenses
    • Top-Up Recordings
    • Subject Recruitment
    • Study Building
    • Dedicated Support
    • Checkout
  • About
    • About Us
    • Contact
    • Downloads
    • Careers
    • Impressum
    • Disclaimer
    • Privacy & Security
    • Terms & Conditions
    • Third-Party Licenses
  • Appgo to app icon
  • Logingo to app icon
Learn
Guide
Videos
Walkthroughs
FAQ
Newsletter Archive
Documents
Classroom
  • 中國人
  • Deutsch
  • Français
  • Español
  • English
  • 日本語
Guide
Videos
Walkthroughs
FAQ
Newsletter Archive
Documents
Classroom
  • 中國人
  • Deutsch
  • Français
  • Español
  • English
  • 日本語
  • Guide
    • GETTING STARTED

      • Task Editor
      • Stimulus Presentation
      • Correctness of Response
      • Objects
      • Events
      • Variables
      • Task Wizard
      • Trial System
      • Study Design
        • Tasks
        • Blocks
        • Sessions
        • Groups
    • FEATURED TOPICS

      • Randomization & Balance
      • Eye Tracking
      • Questionnaires
      • Desktop App
      • Sample Studies
      • Participant Recruitment
      • API Access
        • REST API
        • Webhook API
        • WebSocket API
      • Other Topics

        • Precise Stimulus Timings
        • Multi User Studies
        • Head Tracking in Labvanced | Guide
    • MAIN APP TABS

      • Overview: Main Tabs
      • Dashboard
      • My Studies
      • Shared Studies
      • My Files
      • Experiment Library
      • My Account
      • License & Services
    • STUDY TABS

      • Overview: Study-Specific Tabs
      • Study Design
        • Tasks
        • Blocks
        • Sessions
        • Groups
      • Task Editor
        • Task Controls
        • The Trial System
        • Canvas and Page Frames
        • Objects
        • Object Property Tables
        • Variables
        • System Variables Tables
        • The Event System
        • Text Editor Functions
        • Eyetracking in a Task
        • Head Tracking in a Task
        • Multi-User Studies
      • Settings
      • Variables
      • Media
      • Texts & Translate
      • Launch & Participate
      • Subject Management
      • Dataview and Export
        • Dataview and Variable & Task Selection (OLD Version)
        • Accessing Recordings (OLD Version)
  • Videos
    • Video Overview
    • Getting Started in Labvanced
    • Creating Tasks
    • Element Videos
    • Events & Variables
    • Advanced Topics
  • Walkthroughs
    • Introduction
    • Stroop Task
    • Lexical Decision Task
    • Posner Gaze Cueing Task
    • Change Blindness Flicker Paradigm
    • Eye-tracking Sample Study
    • Infant Eye-tracking Study
    • Attentional Capture Study with Mouse Tracking
    • Rapid Serial Visual Presentation
    • ChatGPT Study
    • Eye Tracking Demo: SVGs as AOIs
    • Multi-User Demo: Show Subjects' Cursors
    • Gamepad / Joystick Controller- Basic Set Up
    • Desktop App Study with EEG Integration
    • Between-subjects Group Balancing and Variable Setup
  • FAQ
    • Features
    • Support Policy & Guidelines
    • Security & Data Privacy
    • Licensing
    • Precision of Labvanced
    • Programmatic Use & API
    • Using Labvanced Offline
    • Troubleshooting
    • Study Creation Questions
  • Newsletter Archive
  • Documents
  • Classroom

Send PostMessage Action

The Send PostMessage action sends a message from your running Labvanced experiment to an external target, such as a parent webpage, a custom application, or an embedded frame, using the browser's postMessage API.

Table of Contents

  • Overview
  • The Two-Sided Setup
  • How it works
  • Action Options
  • Further Reading and Open Materials

Overview

This action is listed under API Actions in the action selection menu.

Selecting the Send PostMessage action from the API Actions category in the Labvanced event editor.

Locating Send PostMessage under API Actions in the event editor.

Common use cases

  • Notifying a parent application (e.g., an LMS or institutional portal) when a participant reaches a certain point or completes a task.
  • Passing a variable value, such as a score, a response, or a condition label, out to an external system in real time.

The Two-Sided Setup

Using postMessage between Labvanced and an external page (such as an iFrame or a parent application) is a two-sided process. Labvanced handles one side: this action sends the message. The other side is the external page, which must be programmed to receive it.

The postMessage API is a standard browser feature. The external page needs a window.addEventListener('message', handler) listener to pick up messages from Labvanced. That listener should also filter by domain, checking that the message origin is Labvanced, so it only acts on messages from a trusted source. You or your developer will need to write that code. An AI coding tool can help generate it quickly if needed.

How it works

When this action fires, Labvanced sends a postMessage to the target window. The message is delivered to any page at the Destination Domain that is listening with a window.addEventListener('message', handler).

The message payload contains the Value to send. If a Key is set, it is included in the payload so the receiving end can identify the message type and handle it accordingly.

The external page is responsible for processing the message. Its listener should check the message origin before acting on it, to ensure it only responds to messages sent from Labvanced.

Upon selecting Send PostMessage, the following configuration will appear:

The Send PostMessage action configuration dialog in Labvanced, showing Destination Domain, Key, and Value to send fields.

Configuration fields for the Send PostMessage action.

Action Options

Menu ItemSend PostMessage Action Options
Destination DomainSpecifies the target origin that should receive the message. The default value is *, which sends to any origin. Replace * with the full target URL (e.g., https://yoursite.com) when the destination is known. Specifying the exact domain is recommended for security.
KeyAttaches an identifier key to the outgoing message. This structures the message payload as Key: value, which the receiving end can use to distinguish different types of messages. Leave empty if no key is needed.
Value to sendDefines the data to include in the outgoing message. Click the edit icon to open the Value-Select Menu and specify what to send: a constant value, a Labvanced variable, or an expression.

Note: The system receiving the message (the parent page or external application) must implement a window.addEventListener('message', ...) listener to handle the incoming postMessage from Labvanced.


Further Reading and Open Materials

  • PostMessage Received Trigger: the paired trigger for listening to incoming postMessages from external sources.
  • Value-Select Menu: how to define what value to send using variables, constants, or expressions.
  • Labvanced Web Bridge Extension: context on how postMessage is used for communication with embedded external websites.
  • Events Overview: a full introduction to the trigger-and-action logic system in Labvanced.