chrome.experimental.notification(丰富通知)和外部网址 [英] chrome.experimental.notification (Rich notifications) and external URLs

查看:104
本文介绍了chrome.experimental.notification(丰富通知)和外部网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下方式打开丰富的通知:

  var options = {
templateType :基本,
标题:John Doe,
消息:Lorem ipsum,
iconUrl:https://www.MyExternalURL.com/image.jpg
};

chrome.experimental.notification.create(notifyId,options,function(id){
console.log(Succesfully created notification);
});

但由于某些原因,这不起作用,但是如果我用以下替换选项:

  var options = {
templateType:basic,
title:request.name,
message:request.message,
iconUrl:chrome.runtime.getURL(/ images / cat.png),
};

并且通知完美无缺。

以下是清单文件中的重要内容:

  {
manifest_version:2,
name :...,
description:...,
版本:...,
图标:{
...
},
content_scripts:[
...
],
background:{
scripts:[background.js]
$ bpermissions:[
tabs,
experimental
],
web_accessible_resources:[
https: //www.MyExternalURL.com/*

}



如何使用外部图片作为iconURL?

只能从扩展程序的包中加载,而不能从网络中加载。这可确保您的扩展程序仅执行您特别批准的代码,从而防止活动网络攻击者恶意重定向您的资源请求。

因此,您的代码不会加载外部JPEG图标 iconUrl:https://www.MyExternalURL.com/image.jpg



请从 https://www.MyExternalURL.com/image.jpg 下载文件并像方法#2一样将其内联。



web_accessible_resources 不会接受任何使用HTTP URL(S)的内容,它只接受一个字符串数组,指定预期可在网页上下文中使用的打包资源的路径(相对于软件包根目录)。



参考




I'm trying to open up a rich notification using the following:

var options = {
    templateType: "basic",
    title: "John Doe",
    message: "Lorem ipsum",
    iconUrl: "https://www.MyExternalURL.com/image.jpg"
};

chrome.experimental.notification.create("notifyId", options, function(id) {
    console.log("Succesfully created notification");
});

But for some reason this does not work, but if I replace the options with the following:

var options = {
    templateType: "basic",
    title: request.name,
    message: request.message,
    iconUrl: chrome.runtime.getURL("/images/cat.png"),
};

And the notification works perfectly.

Here are the important stuff in my manifest file

{
"manifest_version": 2,
"name": ...,
"description": ...,
"version": ...,
"icons": { 
    ...
},
"content_scripts": [
    ...
],
"background": {
    "scripts": ["background.js"]
},
"permissions": [
    "tabs", 
    "experimental"
],
"web_accessible_resources": [
    "https://www.MyExternalURL.com/*"
] 

}

How should I use an external image as the iconURL?

解决方案

Script and object resources can only be loaded from the extension's package, not from the web at large. This ensures that your extension only executes the code you've specifically approved, preventing an active network attacker from maliciously redirecting your request for a resource.

So, your code does not work for loading an external JPEG Icon iconUrl: "https://www.MyExternalURL.com/image.jpg".

Instead download the file from https://www.MyExternalURL.com/image.jpg and put it inline as in approach #2.

More over web_accessible_resources does not accept any content with HTTP URL(S), it only accepts an array of strings specifying the paths (relative to the package root) of packaged resources that are expected to be usable in the context of a web page.

Reference

这篇关于chrome.experimental.notification(丰富通知)和外部网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆