I am trying to set up a simple application using the play framework 2.6 and scala and I can't seem to run inline javascript off my html templates. I keep getting the error:
Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-DdH/amfJizOgk2xZ+Xst5j13qHxPYrrrfT6x/TzfYiA='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
My scala code is:
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import play.twirl.api.Html
class HomeController @Inject()(cc: ControllerComponents) extends
AbstractController(cc) {
def index() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.main("Hello World"))
}
}
And my html.main.html file looks like:
@(title: String)
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<title>@title</title>
<link rel="stylesheet" media="screen"
href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png"
href="@routes.Assets.versioned("images/favicon.png")">
</head>
<body>
<script type = "text/javascript">
document.write("Check");
</script>
<script src = "@routes.Assets.versioned("javascripts/main.js")" type =
"text/javascript"></script>
</body>
</html>
So ideally it should print "Check" on the screen when I connect by the local host. I tried changing my application.conf file to be
play.filters.headers.contentSecurityPolicy = null
But that didn't work either. What else can I try?