Here I need to implant an iframe in my site, and I want to inject some script or css to change the iframe, because of the iframe is not same-origin with my site, so I set a proxy makes it same-origin(localhost:4000).
When I try to get the element from the iframe, an error occured in the console which doesn't meet my expectation.
My site was hosted on localhost:4000 too.
Any idea about this?
<iframe name="editorFrame" id="editorId" src="http://localhost:4000/iframe"></iframe>
// error was raised on
let iframeHead = iframeWin.document.querySelector("head") as HTMLElement;
// the server listens on localhost:4000
// the proxy code
app.use(path, function(req, res) {
return proxy({
target: "http://47.75.177.99",
pathRewrite: {
"^/iframe": "/",
},
onProxyReq(proxyReq, req, res) {
proxyReq.setHeader(
"Cookie",
"tableau_locale=zh; workgroup_session_id=W2fKwkFeSzeC76d0hAAPmA|9vpJTvdHXW9VhaRrMLtwDzIazGYSgCIq; XSRF-TOKEN=NeRc6YfknJ5Vgj03xFwTQ30mftd1Jqlt"
);
},
changeOrigin: true
})(...arguments);
});