您是否尝试过使用反向代理来劫持页面并添加样式以隐藏工具栏?我已经成功地使用Cloudflare Workers实现了这一点。
这种方法的另一个好处是您可以从自己的自定义域名显示仪表板。
您需要一个Cloudflare帐户,在其中配置一个带有以下脚本的工作者。如果您将Cloudflare设置为您的名称服务器,那么您可以在工作者上设置自定义重定向,并使用您的域名。
const upstream = 'app.powerbi.com'
const upstream_path = '/'
const https = true
const disable_cache = true
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request));
})
class RemoveElement {
element(element) {
element.append(`
<style>
.embeddedLandingRootContentLogoVisible { height: 100% }
.logoBarWrapper { display: none }
</style>
`, { html: Boolean })
console.log(`Incoming element: ${element.tagName}`)
}
}
async function fetchAndApply(request) {
const region = request.headers.get('cf-ipcountry').toUpperCase();
const ip_address = request.headers.get('cf-connecting-ip');
const user_agent = request.headers.get('user-agent');
let response = null;
let url = new URL(request.url);
let url_hostname = url.hostname;
if (https == true) {
url.protocol = 'https:';
} else {
url.protocol = 'http:';
}
var upstream_domain = upstream;
url.host = upstream_domain;
if (url.pathname == '/') {
url.pathname = upstream_path;
} else {
url.pathname = upstream_path + url.pathname;
}
let method = request.method;
let request_headers = request.headers;
let new_request_headers = new Headers(request_headers);
new_request_headers.set('Host', upstream_domain);
new_request_headers.set('Referer', url.protocol + '//' + url_hostname);
let original_response = await fetch(url.href, {
method: method,
headers: new_request_headers
})
response = new Response(original_response.body, original_response)
let original_text = null;
let response_headers = original_response.headers;
let new_response_headers = new Headers(response_headers);
let status = original_response.status;
if (disable_cache) {
new_response_headers.set('Cache-Control', 'no-store');
}
new_response_headers.set('access-control-allow-origin', '*');
new_response_headers.set('access-control-allow-credentials', true);
new_response_headers.delete('content-security-policy');
new_response_headers.delete('content-security-policy-report-only');
new_response_headers.delete('clear-site-data');
if (new_response_headers.get("x-pjax-url")) {
new_response_headers.set("x-pjax-url", response_headers.get("x-pjax-url").replace("//" + upstream_domain, "//" + url_hostname));
}
return new HTMLRewriter().on('body', new RemoveElement()).transform(response);
}
一旦准备就绪,新的嵌入式URL将采用以下形式:customdomain.com/view?r=eyJrIjE1NS00......
请查看此存储库以获取进一步说明:
https://github.com/Hugoberry/PowerBI-nologo-proxy