Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:28:36+00:00 2026-06-10T08:28:36+00:00

This is my first Safari extension and thus far I like it quiet a

  • 0

This is my first Safari extension and thus far I like it quiet a bit. I am trying to add an extension bar that interacts with an injected.js page and toggles items on the pages via the jquery .toggle();

I have been able to load jQuery into the page no issue, however when it comes to sending a message from the extension bar to the injected.js I am falling short. I have spent over 8 hours today reviewing the developer pages on Apple. The only thing I have managed to do is

Extension Bar:

<!DOCTYPE html>
<html>
<head>
    <title>Board Tools</title> <!-- Extension Bar -->
    <script type="text/javascript" src="jQuery.min.js"></script>
    <script type="text/javascript">
        const myGlobal = safari.extension.globalPage.contentWindow;

    function ToggleBoard(){ 
        myGlobal.test();    
    }
</script>

</head>
<body>

    <input type="button" id="board" value="Board Toggle" onClick="ToggleBoard();">

</body>
</html>

Global HTML:

<!DOCTYPE HTML>
<html>
<head>
    <title>global page</title>
    <script type="text/javascript">

        function test() {
            alert("1");
            event.target.page.dispatchMessage("test", "test");
            alert("2");
    }

   </script>
</head>
<body> </body>
</html>

Injected.js:

function test(msgEvent) {
    alert(msgEvent.name);
}
// register for message events
safari.self.addEventListener("message", test, false);

I am able to call the ToggleBoard() function from the extension bar. The ToggleBoard() function can call the test() function from the Global HTML. When the test() function is called on the Global HTML page the fist alert fires, the second does not. I have narrowed it down at least that far. I get the way I am trying to send my message is probably wrong, but that is what is says here: https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW1

Just to see if it was a mistake on my part or something goofy with the development page I copied the exact code on their page and used just the Global HTML and Injected.js and I still did not get the result I was looking for.

Solved:
The answer I selected does apply a lot towards the issue I had. It was not the exact answer per-say but it did, along with the comments help me get my code straightened out. In order to get the various extension components to message properly I needed to set the Extension Remote Access to All, and then add URL patterns to the whitelist. My extension only fires on the pages I wanted and I can use messages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:28:37+00:00Added an answer on June 10, 2026 at 8:28 am

    In your test function in the global page, event does not refer to anything, since the function is not an event handler. If you want to target the active tab, use this instead:

    safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('test, 'test');
    

    If, later, you find you want the extension bar or the global page to respond to messages from an injected script, you can add something like this in either place:

    safari.application.addEventListener('message', function (e) {
        if (e.name === 'whatever') {
            e.target.page.dispatchMessage('foo', 'bar');
        }
    }, false);
    

    If you want to send a message from an injected script to the global page or an extension bar, use safari.self.tab.dispatchMessage and have a “message” event handler in place in the global page or extension bar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); $title = $post_id_7->post_excerpt; echo
i have two arrays like this first array Array ( [0228] => Array (
How to create in-app step by step instructions? Like this ( first boot android
I'm programming a preferences panel with a UITableView which looks like this: The first
View this jsFiddle in a WebKit-based browser like Chrome or Safari and then compare
Please check out this example, first in FF, Chrome or Safari: [demo link removed]
This is my first rails app that is not an example out of a
I have successfully written my first Safari Extension. It loops through all input elements
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.