Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新版本 jupyter 似乎导致 PDF 无法显示 / PDF display not working in newer versions of jupyter #1

Closed
bryango opened this issue Aug 12, 2018 · 1 comment

Comments

@bryango
Copy link
Owner

bryango commented Aug 12, 2018

看起来与 jupyter 的验证机制及 Chrome 的安全策略有关,参见 jupyter/notebook#3652.
Seemingly related to jupyter & Chrome's authentication process, see jupyter/notebook#3652.

暂时的解决方案 / Temporary fix:

  1. 安装 PDF.js 插件 或使用 firefox / Use PDF.js extension for Chrome, or simply switch to firefox;
  2. exN.ipynb 中启用内置 PDF 阅读器模式,即修改初始化单元:
#pdfshowOption['mini'] = False
pdfshowOption['mini'] = True
@bryango
Copy link
Owner Author

bryango commented Oct 6, 2018

确认问题由 jupyter 的安全更新 jupyter/notebook#3341 导致。
Due to the security measure introduced in jupyter/notebook#3341 it is nearly impossible to embed pdf in ipynb.

暴力的解决方案 / my fix:
更改 notebook 源码,强行干掉上述 PR!
Simply revert commits by aforementioned PR.

本人的 package 路径为:[...]/anaconda3/lib/python3.7/site-packages/notebook, 变更如下:

Subject: [PATCH] UN-patch #3341

---
 base/handlers.py  | 7 -------
 files/handlers.py | 7 -------
 2 files changed, 14 deletions(-)

diff --git a/base/handlers.py b/base/handlers.py
index e3fbddc..72677c9 100644
--- a/base/handlers.py
+++ b/base/handlers.py
@@ -640,13 +640,6 @@ class Template404(IPythonHandler):
 class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
     """static files should only be accessible when logged in"""
 
-    @property
-    def content_security_policy(self):
-        # In case we're serving HTML/SVG, confine any Javascript to a unique
-        # origin so it can't interact with the notebook server.
-        return super(AuthenticatedFileHandler, self).content_security_policy + \
-                "; sandbox allow-scripts"
-
     @web.authenticated
     def get(self, path):
         if os.path.splitext(path)[1] == '.ipynb' or self.get_argument("download", False):
diff --git a/files/handlers.py b/files/handlers.py
index 7973fd6..b942149 100644
--- a/files/handlers.py
+++ b/files/handlers.py
@@ -26,13 +26,6 @@ class FilesHandler(IPythonHandler):
     a subclass of StaticFileHandler.
     """
 
-    @property
-    def content_security_policy(self):
-        # In case we're serving HTML/SVG, confine any Javascript to a unique
-        # origin so it can't interact with the notebook server.
-        return super(FilesHandler, self).content_security_policy + \
-               "; sandbox allow-scripts"
-
     @web.authenticated
     def head(self, path):
         self.get(path, include_body=False)
-- 
2.18.0

长远的解决方案得看 upstream 的 jupyter/notebook#3652, 本人无能为力。关闭 issue.

bryango added a commit that referenced this issue Nov 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant