Skip to content

Is there a way to call Tauri's API from a page embedded in an iframe? #9967

Answered by muwoo
muwoo asked this question in Q&A
Discussion options

You must be logged in to vote

The issue has been resolved. Just recording my own solution for future reference:

If your iframe and main window have the same domain name, then this may be a good method(Add the following code to the very top of iframe js initialization):

// Override the __TAURI_IPC__ function
window.__TAURI_IPC__ = (args) => {
  //The parent window callback points to the child window
  window.parent[`_${args.callback}`] = window[`_${args.callback}`];

  // Call the function of the parent window 
  window.parent.__TAURI_IPC__(args);
};

First, Tauri will mount the global window.__TAURI_IPC__ in the main window by default, but there is no such function in the child iframe. However, many of Tauri's APIs are…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by muwoo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants