Can't find variable Safari - Safari Extension

Viewed 240

I am trying to build a simple safari extension. The Safari runs on the browser but i get some errors in my console saying "Can't find variable Safari".

According to the safari document link,I have done the below

  1. Add the script files to your extension’s Xcode target.

  2. Add an SFSafariContentScript key to the NSExtension element in your extension’s Info.plist file. The value for this key is an array of dictionaries.

PS: i use the command xcrun safari-web-extension-converter to convert my chrome browser to safari extension

But when i run my extension, the error Cant find variable safari. Any one has an idea how to resolve this ? Been on this for days.

manifest.json

{
  "manifest_version": 2,
  "name": "Spotiga",
  "version": "1.0.0",
  "description": "Musica Extension",

  "background": {
    "scripts": ["background.js"],
  },

"content_scripts":
[
  {
    "matches": ["*://localhost/*"],
    "all_frames": true,
    "js": ["content_script.js"],
    "run_at": "document_idle"
  }
]
}

JS

var newElement = document.createElement("img");
   newElement.src = safari.extension.baseURI + "myCat.jpg";
   document.body.insertBefore(newElement,
   document.body.firstChild);
0 Answers
Related