Error occurring when attempting to pass messages within an iframe on a sandboxed page in a Chrome extension

Whenever I try to utilize my popup page for a chromium extension as a conduit for communication between the background page and a page shown within an iframe on the popup, I encounter the following error. I required a sandboxed environment to execute Vue.js but also needed access to retrieve data from chrome.storage and interact with similar objects in order to receive data packets and send commands to the background page when needed.

An Uncaught SecurityError is triggered: Sandbox access violation - a frame at "chrome-extension://kncjlbkddbibekfmmljfpibdgjfdegeb" has been blocked from accessing another frame at "chrome-extension://kncjlbkddbibekfmmljfpibdgjfdegeb". The requesting frame lacks the “allow-same-origin” flag due to sandboxing.

The code snippet below pertains to the pipe popup page:

//please look at it as if block comments aren't commented out
//this is needed  due to SO not having chrome.* available.
//although line comments are real comments.

let displayFrame = document.getElementById('displayFrame');
let displayPort = displayFrame.contentWindow;
/*
let backgroundPort = chrome.extension.connect({
  name : "Extension Connection"
});
*/

// Forwarding from background to index.
/*
backgroundPort.onMessage.addListener((msg) => {
  displayPort.postMessage(msg, "*");
});
*/

// Forwarding from index to background.
window.addEventListener("message", function(msg) {
  /*
    backgroundPort.postMessage({
      data : msg.data
    });
  */
});
<!doctype html>
<html lang='en'>

<head>
  <meta charset='UTF-8' />
  <script src="../scripts/popup.js" defer>
  </script>

  <style>
    * {
      box-sizing: border-box;
      opacity: 1.0;
      margin: 0px;
      padding: 0px;
      resize: none;
    }
  </style>
</head>

<body style="width : 300px; height: 500px;">
  <iframe id="displayFrame" sandbox="allow-same-origin allow-scripts" src="./index.html" style="width: 300px; height: 500px" frameborder="0"> </iframe>
</body>

</html>

The specifics of background.js and index.html/js are deemed irrelevant by me, since both efficiently forward messages to their respective areas of the aforementioned code, which has been verified through console log messages. The problem arises only when modifications are made in index.js involving a Vue.js variable. Attempts were made directly on the Vue object (referred to as vm in the documentation) and internally via attaching a message listener to the window during the mounted hook event. It appears that the wrapped setters for each variable, enabling Vue to monitor state changes, result in this issue. I am seeking guidance on how to resolve this error.

I have encountered no disturbances with the extension overall; message passing functions as expected, and setting Vue variables or calling functions works flawlessly. However, whenever I open the popup page, the error surfaces in the console of the background pages. Is this a concern, and can it be rectified?

Answer №1

After successfully resolving the issue at hand, it became evident that the error was specifically triggered when assigning the value of a Vue variable to event.source in the index.js file within

window.addEventListener("message", (event) => { ... })
. It seems there is a discrepancy between how Vue tracks variables and the nature of the variable being a window object from the sender. Realizing that the sender was actually the parent of the iframe all along, I tackled my problem by:

  • Omitting the introduction packet that stored the event.source for command transmission.
  • Opting to send commands through window.parent.postMessage instead of the previous method using this.vueVariable.postMessage.

I trust this explanation will be beneficial for anyone encountering a similar issue in the future. The solution had been right in front of me the entire time. With these adjustments, the extension now operates without any errors, enabling seamless communication in both directions with successful data assignments.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the dimensions of the bootstrap dropdown to match the dimensions of its textbox

The second textbox features a bootstrap dropdown with extensive content that is overflowing and extending to other textboxes below it. I am looking for a way to resize the dropdown to fit the size of its corresponding textbox. UPDATE: I want the dropdown ...

Tips for selecting React component props based on a specific condition

Here is a React component that I have: <SweetAlert show={this.props.message} success title={this.props.message} onConfirm={this.props.handleCloseAlert}> </SweetAlert> Upon using this component, I receive the following alert ...

Is there a way to extract the timestamp in JavaScript from a string that includes the name of the timezone database?

Given the string: "2022/05/01 03:10:00", I am seeking to create a Date object with Chile's UTC offset. The challenge lies in the fact that due to Daylight saving time (DST), the offset changes twice annually. How can I obtain that Date obj ...

I would like to know the best approach to utilizing a PHP array or JSON response within JavaScript

Let me present my workflow briefly. While I initiate an Ajax call from the index.phtml file, the Ajax response is as follows: Array ( [Data] => Array ( [0] => Array ( [PlayerId] => 20150 ...

Issue with loading dynamic content on a webpage using HTML and JavaScript through AJAX

I am currently using the jQuery UI Tabs plugin to dynamically load HTML pages through AJAX. Here is the structure of the HTML code: <div id="tabs"> <ul> <li><a href="pageWithGallery.html" title="pageWithGallery">Gallery< ...

Using `href="#"` may not function as expected when it is generated by a PHP AJAX function

I am facing an issue with loading html content into a div after the page has loaded using an ajax call. The setup involves a php function fetching data from the database and echoing it as html code to be placed inside the specified div. Here is my current ...

The process of departing a SocketIO room and switching to a different room logic

I am wondering how I can leave the Room when I click on a new Room Here is what my page looks like: https://i.sstatic.net/vuwv0.png The list on the left side is from the MySQL Server and it displays a list of my chats. Each Room name has an id value whi ...

Is there a way to incorporate a fade-in effect when I trigger the expand function in this script?

I recently came across a jQuery plugin for expanding and collapsing content. I am interested in adding a fade-in effect to this plugin specifically when the EXPAND button is clicked. How can I accomplish this? $(document).ready(function () { var maxlines ...

How can we prevent components from rendering in React when their state or props have not changed?

I encountered a problem in my project where I have a main component that serves as the parent component of my project. Inside this main component, I have defined routes for other components and directly imported some components like a Side Navbar and Login ...

Set the value of one email input to another email input in AngularJS

I'm having trouble trying to link an email input field to another in angularjs without success. Here is what I have attempted so far: <div class="row-fluid"> <div class="control-group span12"> <label for="email">Email</labe ...

Importing WebAssembly dynamically can sometimes lead to complications with the order of execution

I am attempting to load a WASM library from another node js application, both utilizing webpack. Within the WASM library, I have the following code snippet exporting the functionality. export default import("./pkg") .then(s => { le ...

AngularJS JSON Array

I have an array containing multiple objects in JSON, as well as a select element that contains an array. Depending on the selection made in the first array, another select box will be dynamically loaded right below it. HTML Code <div class="list"> ...

Is it secure to use console.time() in a Node.js environment?

Looking at a small snippet of node.js code, here's what I have: console.time("queryTime"); doAsyncIOBoundThing(function(err, results) { console.timeEnd("queryTime"); // Process the results... }); Running this on my development system gives m ...

Create a custom npm package that is compatible with frontend environments like create-react-app. Ensure you have a suitable loader in place to handle the specific file type of the module

After developing a node module and releasing it as a node package, I encountered an issue when trying to use it in frontend applications (specifically with a 'create-react-app'). The error message that appeared stated: Module parse failed: Unexp ...

iOS is not receiving JSON data in the response headers

I am currently utilizing the CocoaHTTPServer for establishing my server connection. However, I encountered an issue with retrieving JSON data in the header file of my HTML page (web client). Here is the code snippet : HTML Page : endAPSession: funct ...

Experiencing a 400 error while transitioning from ajax to $http?

I am facing an issue while trying to make a GET request using $http instead of ajax. The call functions perfectly with ajax, but when attempting the same with $http, I encounter a 400 (Bad Request) error. I have referenced the Angular documentation and bel ...

Include a CSS file from an external JavaScript file

Is there a way to include an external CSS file in an external JS file? I am trying to reference and load Default.css inside Common.js like the image below shows. Any suggestions are greatly appreciated! BB ...

Turning JavaScript Object into a Decimal Value

I've been working on an application where I want to be able to add up the columns of an HTML table. I managed to add inputs to the table successfully, but when trying to sum up the columns, I keep getting a "NaN" error. /* Function for calculating ...

The submit button seems to be unresponsive or unreactive

As a newcomer to Angular 2 and Typescript, I am in the process of building a web application. I have created several input fields and, following user submission via a button, I want to log the inputs to the console. However, it seems like my button is not ...

Can you implement https.createServer in a Chrome app?

Currently, I am exploring the chromify approach for developing a Chrome app in NodeJS. However, I have encountered an issue where node-chromify only supports HTTP servers and not HTTPS. Therefore, my query is whether there is a solution to mount a single ...